Flutter 避免底部导航栏中的持久状态管理
我正在使用库 persistent_bottom_nav_bar
并将 stateManagement
选项设置为 false,因为在页面中我希望每次进入页面时都使用未来的构建器。
问题是未来的构建器不再被调用,或者它被调用但页面仍然是以前的状态。
这是我的 PersistentTabView
:
PersistentTabView(
context,
screens: _NavScreens(),
items: _navBarsItems(),
confineInSafeArea: true,
backgroundColor: Colors.white,
handleAndroidBackButtonPress: true,
resizeToAvoidBottomInset: true,
hideNavigationBarWhenKeyboardShows: true,
hideNavigationBar: false,
stateManagement: false,
decoration: NavBarDecoration(
border: Border(top: BorderSide(color: Colors.grey, width: 0.5))
),
popAllScreensOnTapOfSelectedTab: true,
navBarStyle: NavBarStyle.style6,
),
在示例中,我第一次进入页面时,将调用未来构建器并显示列表。如果我更改屏幕并返回到前一个屏幕,则未来的构建器将无法工作。
I'm using the library persistent_bottom_nav_bar
and I settled the stateManagement
option equals to false because in a page I want to use a future builder each time that I enter the page.
The problem is that the future builder is not called anymore, or It is called but the page is still with the previous state.
This is my PersistentTabView
:
PersistentTabView(
context,
screens: _NavScreens(),
items: _navBarsItems(),
confineInSafeArea: true,
backgroundColor: Colors.white,
handleAndroidBackButtonPress: true,
resizeToAvoidBottomInset: true,
hideNavigationBarWhenKeyboardShows: true,
hideNavigationBar: false,
stateManagement: false,
decoration: NavBarDecoration(
border: Border(top: BorderSide(color: Colors.grey, width: 0.5))
),
popAllScreensOnTapOfSelectedTab: true,
navBarStyle: NavBarStyle.style6,
),
In the example the first time that I enter in the page the future builder is called and the list appears. If I change screen and I go back in the previous screen the future builder is not working.
Example:
https://imgur.com/a/jJWJPvU
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对 persistent_bottom_nav_bar 的 stateManagement 选项也有同样的问题。我将其描述为 false,它对状态没有影响所以我找到了另一个解决方案。我在我的项目中使用了 bloc 和提供程序。我用全局键解决了它,我将分享我的代码希望它有效。
使用全局键方法,您可以使用静态底部导航栏,并且可以避免持久状态管理。希望它对您有所帮助。
i had same problem with persistent_bottom_nav_bar's stateManagement option.I describe it to false it did not effect to state.So i found another solution.I was using bloc and provider in my project.I solved it with global keys i'll share my code hope it works.
With global key method you can use your bottom nav bar static and you can avoid persistent state management.Hope it helps you.