什么是最好的方式来运行计时器在botom导航栏与块和导航到网页与out影响计时器状态我使用底部导航栏在Flutter与块,在底部导航栏中的每个项目有自己的块。问题是,在第一页我运行一个计时器,它得到重置,而导航到另一个页面在BNB
slmsl1lt1#
这个问题有两个解决方案,请选择您喜欢的一个。1.添加由所有底部导航项监视的额外块,即使底部导航索引已更改,也不会被丢弃。1.使用IndexedStack保存状态。
IndexedStack
Scaffold( appBar: AppBar(), body: IndexedStack( index: _currentIndex, children: _routes.map((route) => route.page).toList(), ), bottomNavigationBar: BottomNavigationBar( currentIndex: _currentIndex, onTap: _onPageChanged, items: _routes.map((route) { return BottomNavigationBarItem(icon: route.icon, label: route.name); }).toList(), ), )
字符串
1条答案
按热度按时间slmsl1lt1#
这个问题有两个解决方案,请选择您喜欢的一个。
1.添加由所有底部导航项监视的额外块,即使底部导航索引已更改,也不会被丢弃。
1.使用
IndexedStack
保存状态。字符串