Warm tip: This article is reproduced from stackoverflow.com, please click
flutter state-management flutter-provider flutter-navigation flutter-state

Preserve page state while using Navigator

发布于 2020-03-30 21:14:01

I have a PageView( ) displaying four different pages and a BottomNavigationBar used to navigate to those pages. I have a FloatingActionButton on the first page when I use Navigator.push() to push the second route and Navigator.pop to pop it out the initial page rebuilds again, The same thing happens when I use it on the fourth page too, The first screen is returned instead of the same screen as I'm performing an operation on that page. So how do I navigate back to the same page while preserving sate of that page?

I have used AutomaticKeepAliveClient mixin to preserve the state of the pages while navigating through the bottom navigation bar but not able to do so using Navigator.

This article by Andrea Bezzito does cover some parts of it but I wasn't sure if that is exactly what I wanted. so wanted to look for alternative solutions if any available.

Thank you.

Questioner
sameer kashyap
Viewed
16
mskolnick 2020-01-31 21:48

What you're looking for is called Provider. Here is a very simple example of how you could use provider. https://github.com/m-Skolnick/provider_example_flutter