flutter - 单击 PersistentBottomNavBarItem 时弹出所有屏幕
问题描述
我使用 persistent_bottom_nav_bar 将 BottomNavigationBar 保留在应用程序中。
在BottomTab A中,出现屏幕A1,我单击屏幕A1中的按钮导航到屏幕A2并保留BottomNavBar。在我选择 BottomTab B => 出现屏幕 B 之后。但是当我选择 BottomTab A => 出现屏幕 A2 时(我想在再次单击 BottomTab A 时出现屏幕 A1)。
帮我!!!!!
解决方案
使用此代码实现底部导航栏,并根据您的要求对其进行自定义...
class BottomNavBar extends StatefulWidget {
const BottomNavBar({Key? key}) : super(key: key);
@override
_BottomNavBarState createState() => _BottomNavBarState();
}
class _BottomNavBarState extends State<BottomNavBar> {
int pageIndex = 0;
List<Widget> pageList = <Widget>[Home(), Profile(), Setting()];//Here define your own screens
@override
Widget build(BuildContext context) {
return Scaffold(
body: pageList[pageIndex],
bottomNavigationBar: BottomNavigationBar(
fixedColor: Colors.redAccent[400],
currentIndex: pageIndex,
onTap: (value) {
setState(() {
pageIndex = value;
});
},
// type: BottomNavigationBarType.fixed,
items: [
BottomNavigationBarItem(
activeIcon: Icon(
Icons.home,
color: AppColors.black,
),
icon: Icon(
Icons.home,
color: AppColors.grey,
),
label: ""),
BottomNavigationBarItem(
activeIcon: Icon(
Icons.person,
color: AppColors.black,
),
icon: Icon(
Icons.person,
color: AppColors.grey,
),
label: ""),
BottomNavigationBarItem(
activeIcon: Icon(
Icons.settings,
color: AppColors.black,
),
icon: Icon(
Icons.settings,
color: AppColors.grey,
),
label: ""),
]));
}
}
推荐阅读
- python-3.x - aiohttp 中的 os.kill 与 process.terminate
- bazel - 如果我的 bazel 目标生成未在其输出中指定的文件,我会出错吗?
- laravel-5 - 拉拉维尔 5.6。文件属性不来
- apache-flink - Flink 中的 RocksDBStateBackend 如何将数据溢出到磁盘?
- python - 如何重命名文件以包含文件路径?
- django - 使两个外键在同一模型上唯一
- javascript - moment.js 如何以特定格式打印本周
- android - 创建新项目后activity_main.xml 中的错误
- excel - 将多个值写入一个单元格 - VBA
- python - 字典列表的问题