【发布时间】:2020-07-18 18:58:02
【问题描述】:
我有一个包含三个页面的应用程序,用户可以使用底部导航栏进行导航。尽管如此,我希望在用户返回时重建三个页面之一(因此:删除当前状态并从头开始重新渲染)。
我的导航代码如下。
三页选项:
static List<Widget> _widgetOptions = <Widget>[
PostFeed(),
Profile(),
HabitList(),
];
在页面选项之间切换(稍后在底部导航中):
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
在脚手架上:
body: _widgetOptions.elementAt(_selectedIndex),
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
),
BottomNavigationBarItem(
icon: Icon(Icons.list),
),
],
currentIndex: _selectedIndex,
onTap: _onItemTapped,
),
使用此代码,当我在它们之间切换时,所有页面的状态都保持不变。当用户点击特定的底部导航图标时,我现在只想动态加载一个(PostFeed)。
现在有人怎么做吗?
非常感谢!
【问题讨论】:
-
我建议阅读这篇文章以更好地了解底部导航栏:medium.com/@meysam.mahfouzi/…
标签: flutter widget state bottomnavigationview