dart Flutter block底部导航栏

fjaof16o  于 5个月前  发布在  Flutter
关注(0)|答案(1)|浏览(78)

什么是最好的方式来运行计时器在botom导航栏与块和导航到网页与out影响计时器状态
我使用底部导航栏在Flutter与块,在底部导航栏中的每个项目有自己的块。问题是,在第一页我运行一个计时器,它得到重置,而导航到另一个页面在BNB

slmsl1lt

slmsl1lt1#

这个问题有两个解决方案,请选择您喜欢的一个。
1.添加由所有底部导航项监视的额外块,即使底部导航索引已更改,也不会被丢弃。
1.使用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(),
  ),
)

字符串

相关问题