简体   繁体   English

使用 Flutter 中的 BottomNavigationBar 导航页面时的标准做法?

[英]Standard practice when navigating pages using BottomNavigationBar in Flutter?

I am trying to understand the standard practice of using the BottomNavigationBar for navigating/rendering in Flutter.我试图了解在 Flutter 中使用 BottomNavigationBar 进行导航/渲染的标准做法。 I've been looking at examples and have seen multiple ways of doing this.我一直在查看示例,并看到了多种方法。

  1. When a tab is selected do a setstate and render the body.当一个选项卡被选中时,执行一个 setstate 并渲染 body。
  2. When a tab is selected use navigator to navigate to a new screen/page while persisting the BottomNavigationBar选择选项卡时,使用导航器导航到新屏幕/页面,同时保持 BottomNavigationBar

Which is the right thing to do or it depends?哪个是正确的事情,或者取决于什么?

It depends on what you want to achieve.这取决于您想要达到的目标。

If you render a new page (with navigate) the page will slide in from right or from wherever you want and you can add a back button to go back to the previous page.如果您呈现一个新页面(带有导航),该页面将从右侧或从您想要的任何位置滑入,您可以将后退按钮添加到 go 回到上一页。

If you use setState to render new content the content will just be replaced.如果您使用 setState 呈现新内容,则内容将被替换。 Therefore it's a completely different user experience.因此,这是一种完全不同的用户体验。

With a ButtomNavigationBar I suggest to use setState, to just replace the content.使用 ButtonNavigationBar 我建议使用 setState 来替换内容。 This is the usual behavior of a ButtomNavigationBar这是 ButtonNavigationBar 的通常行为

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用BottomNavigationBar导航时,如何在颤动中保留小部件状态? - How to preserve widget states in flutter, when navigating using BottomNavigationBar? Flutter 在使用 BottomNavigationBar 加载的页面之间切换 - Flutter switch between pages loaded using BottomNavigationBar Flutter 使用一个 Scaffold 使用 BottomNavigationBar 更改页面 - Flutter Changing pages with BottomNavigationBar using one Scaffold 如何使用 flutter 中的底部导航栏移动到新页面? - How to move to a new pages using bottomnavigationbar in flutter? Flutter bottomNavigationBar不能更改页面 - Flutter bottomNavigationBar not change pages Flutter:使用BottomNavigationBar时如何传递变量? - Flutter: How to transfer variables when using BottomNavigationBar? 在底部导航栏中更改页面时,强制 Flutter 不会丢失数据 - Force Flutter not lose data when changing pages in the BottomNavigationBar 导航到另一个屏幕而没有底部导航栏图标颤动,但将底部导航栏保留在另一个屏幕中 - Navigating to another screen without bottomNavigationBar Icons in flutter but keeping the bottomNavigationBar in anotherScreen 颤动:bottomNavigationBar 无法使用 WebView 在 html 页面之间切换 - flutter: bottomNavigationBar cannot switch between html pages using WebView BottomNavigationBar保存偏移位置并导航到细节抖动 - BottomNavigationBar saving offset position and navigating to details flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM