我有4页在flutter项目,我想:
1-当用户按下手机的后退按钮时,显示底部导航栏
页面与主页之间的路由。
2-当用户未使用bottomnavigationbar
进入页面时,bottomnavigationbar
中该页面的图标将与该页面同步。
null
您可以在scaffold
内的bottomnavigationbar
属性内提供两个内容:
第一个是bottomnavigationbar
,第二个是tabbar
>
使用bottomnavigationbar
var _currentIndex = 0;
var _pages = [
HomePage(),
Page2(),
Page3()
Page4()
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Bottom Navigation Bar'),
),
body: _pages[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
onTap: (int index) {
setState(() {
_currentIndex = index;
});
},
currentIndex: _currentIndex,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(Icons.message),
title: Text('Page2'),
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
title: Text('Page3')
),
BottomNavigationBarItem(
icon: Icon(Icons.photo),
title: Text('Page4')
),
],
),
);
}
null