【问题标题】:Flutter navigation to TabNav page from other page从其他页面 Flutter 导航到 TabNav 页面
【发布时间】:2018-03-25 00:16:20
【问题描述】:

我有一个带有 TabBarview 的底部导航栏,如下所示:

@override
  Widget build(BuildContext context) {
    return new Scaffold(
      //drawer: _drawer,
      appBar: new AppBar(automaticallyImplyLeading: false,
          title: new Text(_choice.title), actions: getAppBarActions(context)),
      bottomNavigationBar: new Material(
          color: CupertinoColors.lightBackgroundGray,
          //color: c,
          child: new Container(
            height: 50.0,
            child: new TabBar(
              controller: controller,
              //labelColor: Colors.grey,
              tabs: mytablist,
              labelStyle: new TextStyle(fontSize: 10.0),
              labelColor: CupertinoColors.activeBlue,
              unselectedLabelColor: CupertinoColors.inactiveGray,
              isScrollable: true,
              indicatorWeight: 1.0,
              indicatorColor: CupertinoColors.activeBlue,
              //indicatorPadding: new EdgeInsets.only(bottom: 5.0),
            ),
          )),
      body: new TabBarView(
        controller: controller,
        children: _tabWidgets(),
      ),
    );
  }

我有导航到的课程页面,我也导航到没有底部导航的 tabbarview 页面,但是我希望能够导航到底部导航中的页面之一,但是当我使用像这样:

Navigator.of(context)..pushReplacementNamed(Chat.ChatServerPage.routeName);

它转到页面但没有应用栏或底部导航栏,有人知道如何完成吗?我已经尝试了所有我能找到的东西。任何帮助将不胜感激。

【问题讨论】:

  • 您是否尝试过包装路由引用的小部件返回一个新的 Scaffold? DRY 的一个简单方法是创建一个父窗口小部件,该窗口小部件返回一个带有 TabBarView 和 AppBar 的新 Scaffold。
  • 路由中引用的页面确实返回了一个新的 Scaffold,但是如果我还告诉它有一个 appbar 和 tababr,那么当它通过 tabnav 正常调用时,它有 2 个 appbars 和 2 个底部导航 tabnav 的,因为它通常已经从材料应用程序中获取它

标签: flutter


【解决方案1】:

检查您的小部件层次结构。通常MaterialApp 小部件是顶级的,它包含Navigator 小部件。这就是“导航”取代整个屏幕的原因。

您可以使用不同的方式来实现这一点:

  1. 每个页面都有自己的Scaffold,带有 AppBar 和 NavBar。 Related question

  2. 可以有多个导航器。并且可以在脚手架主体中添加单独的导航器。 Related question

【讨论】:

    猜你喜欢
    • 2020-07-29
    • 2020-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 2013-05-11
    • 1970-01-01
    相关资源
    最近更新 更多