I have a series of stateful widgets in a PageView managed by a PageController. I am using pageController.jumpToPage(index)
to switch pages. When switching pages
keepPage: true
is the default behavior; it means that the PageController
will remember what page it's on if it is destroyed and recreated. This isn't what you want.
Instead, pass a page-specific PageStorageKey to the constructor of the pages. This helps Flutter give a unique storage bucket to your page. Then in your State
that you want to have restored to its previous condition, you can use PageStorage.of(context)
to get the storage bucket, which you can read
values from in initState
and write
values to when they change. You can see an example in ExpansionTile.