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

标签 navigation dart flutter

我有一个场景,我有 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/

相关文章:

firebase - 如何在 Crashlytics/Flutter (Android) 中查看 Dart 代码堆栈跟踪而不是 Java 代码堆栈跟踪

css - 为什么我的导航栏标签没有包含 CSS?昨天在工作,所以我把它弄坏了?

dart - 是否可以在 pubspec 中为包依赖项赋予不同的名称

Flutter 从表单中提取所有键值

android - 如何在WebView上删除AppBar?

flutter - 将菜单项重定向到另一个页面

android - flutter : Picasso or Universal Image loader equivalent

html - 下拉子菜单不起作用

ruby-on-rails - rails_admin 导航隐藏模型不起作用

javascript - AngularJS 导航