【问题标题】:How to modify parent FloatingActionButton on flutter?如何在颤动上修改父 FloatingActionButton?
【发布时间】:2020-07-13 19:08:39
【问题描述】:

我正在制作一个应用程序,其中我必须通过 BottomNavigationBar 路由页面,并且每个页面都有自己的嵌套路由。该应用程序包含一个主 FloatingActionButton,它居中并停靠在 BottomNavigationBar。问题是我想控制 FAB 从每个嵌套路由内部执行的操作。问题是,如果我在每个嵌套路由中创建一个 FAB,则该按钮将不会停靠在 BottomNavigationBar。下面是一些图片。任何人都可以帮忙吗?提前致谢。

我有什么:

我想要什么:

【问题讨论】:

  • 用按钮分享代码

标签: flutter flutter-layout floating-action-button


【解决方案1】:

这是你要问的吗?如果没有,请分享一些解决问题的代码

更新

 Scaffold(
      appBar: AppBar(
        title: Text('Test'),
      ),
      body: _screenList[_screenIndex],
      bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: _screenIndex,
          onTap: (index) {
            print(index);
            setState(() {
              _screenIndex = index;
            });
          },
          items: [
            BottomNavigationBarItem(
              icon: Icon(Icons.inbox),
              title: Text('Screen1'),
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.search),
              title: Text('Screen2'),
            ),
          ]),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      floatingActionButton: FloatingActionButton(
        child: Icon(
          Icons.android,
        ),
        onPressed: () {
          _screenIndex == 0
              ? print('hello from screen1')
              : print('hello from screen2');
        },
      ),
    );

输出

【讨论】:

  • 不。他有这个底部导航栏作为根,它只构建一次,嵌套页面在它下面,它作为根大多数小部件。当页面改变时,工厂保持不变并且不是重建的只有页面改变了。他想根据当前打开的页面来处理FAB的onTap功能。
  • @HaroonAshrafAwan 好的,希望我们能得到一些代码来重现这种行为。首先,我不明白他为什么要在每一页上重新创建 FAB。他可以轻松地控制主页上每个页面的功能。没有代码,我真的无能为力
  • @LonelyWolf 这正是我想知道的。我怎么能从它的孩子控制主页内的FAB。因为有些页面应该隐藏FAB
  • @AyltonAlmeida OK 检查更新的代码如何控制您在其他子页面中的 fab 按钮的功能。
猜你喜欢
  • 2020-09-22
  • 1970-01-01
  • 1970-01-01
  • 2019-06-04
  • 2022-01-24
  • 1970-01-01
  • 1970-01-01
  • 2019-08-30
  • 2021-10-22
相关资源
最近更新 更多