【发布时间】:2020-07-02 23:55:42
【问题描述】:
我制作bottomNavigationBar如下
List<Widget> pages = [
Dashboard(),
AllServices(),
InformationPage(),
];
int _selectedIndex = 0;
Widget _bottomNavigationBar(int selectedIndex) {
return BottomNavigationBar(
onTap: (int index) => setState(() => _selectedIndex = index),
currentIndex: selectedIndex,
type: BottomNavigationBarType.fixed,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: new Icon(Icons.home),
title: new Text("Dashboard"),
),
BottomNavigationBarItem(
icon: new Icon(Icons.location_on),
title: new Text("AllServices"),
),
BottomNavigationBarItem(
icon: new Icon(Icons.person),
title:new Text("InformationPage"),
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: _bottomNavigationBar(_selectedIndex),
body: pages[_selectedIndex],
);
}
如果用户在页面之间导航,一切都是正确的,但是 AllServices 类有两个条件来呈现两个不同的小部件,我希望如果用户在 AllServices 页面中再次 ontap AllServices 底部导航 AllServices 页面再次重建但 ontap 不适用于同一页面重新构建它,我该如何解决这个问题?
【问题讨论】:
-
该解决方案是否适合您。
-
@sagaracharya 感谢您的帮助,但 Navigator.push 并没有像底部导航底部的 onTap 那样提供操作
标签: flutter flutter-bottomnavigation