gpt4 book ai didi

navigation - Flutter 中带有导航栏的永久 View

转载 作者:IT老高 更新时间:2023-10-28 12:34:20 28 4
gpt4 key购买 nike

我有一个场景,我有 2 个 View :

  • 查看 1
  • 查看 2

从 View 1 按下按钮时,会调用 Navigator.of(context).pushnamed('/view2'),这会将 View 2 推送到屏幕上。在这种情况下,整个 View 从 View 1 过渡到 View 2。

当从 View 1 转换到 View 2 时,是否可以有一个仍保留在屏幕上的永久 View ?类似于 Soundcould 在底部使用播放控件的方式。无论您导航到哪个屏幕,它始终永久显示在哪里。这张图描述了我想要实现的目标: enter image description here

在 iOS 上,我可以通过在 ViewController 中的 ContainerView 中使用 Navigation Controller 来实现此目的,然后让永久 View 占据 ContainerView 正下方的屏幕底部

最佳答案

您可以在此处使用相同的方法。父窗口小部件可以有两个部分: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(),
);
}

关于navigation - Flutter 中带有导航栏的永久 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45511549/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com