我有一个场景,我有2个观看次数:
在按钮上按下按钮,将调用Navigator.of(上下文).pushnamed(' / view2'),将视图2推送到屏幕。在这种情况下,整个视图将从视图1转换为视图2.
从View 1转换到View 2时,是否可以使用永久视图仍然保留在屏幕上?类似于Soundclould在底部播放控件的方式。无论您导航到哪个屏幕,它始终会永久显示。该图描绘了我想要实现的目标:
在iOS上,我可以通过在ViewController中的ContainerView中安装导航控制器来实现这一点,然后让永久视图占据ContainerView正下方的屏幕底部
答案 0 :(得分:8)
您可以在此处使用相同的方法。父窗口小部件可以包含两部分:Navigator和PermanentView。通过推送路线,您将只更改Navigator小部件。 演示:
import 'package:flutter/material.dart';
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
Route _onRoute(RouteSettings settings) {
final str = settings.name.split("/")[1];
final index = int.parse(str, onError: (s) => 0);
return new MaterialPageRoute(
builder: (BuildContext context) => new Home(index: index));
}
@override
Widget build(BuildContext context) {
return new Column(
children: <Widget>[
new Expanded(
child: new MaterialApp(
title: 'Flutter Demo',
onGenerateRoute: _onRoute,
),
),
new Container(
height: 44.0,
color: Colors.blueAccent,
child: new Center(
child: new Text("permanent view"),
),
)
],
);
}
}
class Home extends StatelessWidget {
Home({Key key, this.index}) : super(key: key);
final int index;
@override
Widget build(BuildContext context) => new Scaffold(
appBar: new AppBar(
title: new Text("View ${index}"),
),
body: new Center(
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Text("View ${index}"),
new FlatButton(
onPressed: () =>
Navigator.of(context).pushNamed("/${index + 1}"),
child: new Text("Push"))
],
),
),
);
}
void main() {
runApp(
new MyApp(),
);
}