首页 > 解决方案 > 如何在颤动上修改父 FloatingActionButton?

问题描述

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

是)我有的 :

在此处输入图像描述

我想要什么:

在此处输入图像描述

标签: flutterflutter-layoutfloating-action-button

解决方案


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

更新

 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');
        },
      ),
    );

输出

在此处输入图像描述


推荐阅读