flutter - 如何在颤动上修改父 FloatingActionButton?
问题描述
我正在制作一个应用程序,在该应用程序中我必须通过 BottomNavigationBar 路由,并且每个页面都有自己的嵌套路由。该应用程序包含一个主 FloatingActionButton,它居中并停靠在 BottomNavigationBar。问题是我想控制 FAB 从每个嵌套路由内部执行的操作。问题是,如果我在每个嵌套路由中创建一个 FAB,则该按钮将不会停靠在 BottomNavigationBar。下面是一些图片。任何人都可以帮忙吗?提前致谢。
是)我有的 :
我想要什么:
解决方案
这是你要问的吗?如果不是,请分享一些解决问题的代码
更新
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');
},
),
);
输出
推荐阅读
- android - FirebaseMessagingService 扩展服务类在 android 7.1.1 设备中被破坏
- html - 如何使用 href 从 URL 中删除查询字符串
- reactjs - ReactJS 中的三元运算符混淆
- reactjs - 是否可以在 Ant Design 中禁用空表的标题?
- php - axios 接收 array_filter 结果作为对象而不是数组
- javascript - 如何让 Ionic 3 应用程序从 Ionic 1 应用程序使用的 window.localstorage 读取现有数据?
- react-native - 无法解析模块“react-redux”...模块“react-redux”在加速模块映射中不存在
- c++ - 如何正确格式化此打印功能?
- java - Json 没有被写入文件
- javascript - 在 JS 中获取用户定义的 CSS 值