简体   繁体   中英

How should I implement navigation between fragments in Flutter?

I have a native Android app that I am translating to Flutter, and I am not sure that I'm on the right track. I implemented the bottom navigation bar functionality by following the documentation, but I'm not sure what's the best way to navigate between what were Fragments in the native android project. For every widget I select with the BottomNavBar, I need further "pages", while the BottomNavBar has to stay on the screen, and I also need to pass data further "down" the navigation graph.

I thought about creating a custom widget which stores the subpage you are on, same way as I did with the BottomNavBar, but this seems like a hack, especially that I would also have to store the parameters that I have to pass to the new "fragment", and the pages should keep their state after navigating away and back.

Is there a better way to implement this functionality?

I use the IndexedStack as this article elaborates. I think it's probably a good solution.

https://pub.dev/packages/persistent_bottom_nav_bar/

It occurred to me after asking that I should check for a package, and here it is, does what I need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM