Prevent page to rebuild using bottom navigation in flutter

64 views Asked by At

Is there a way to prevent a page from being rebuilt when using bottom navigation bar in Flutter?

I have a bottomNavigationBar with 3 items. There are some riverpod providers running for the different pages. I need the first page to not rebuild when I navigate to other pages because there are providers behind it running some tasks that should not be aborted such that when I return to the page, the state should already be updated. Basically I have a google map (https://pub.dev/packages/google_maps_flutter) that is listening to a position stream and being updated. I would love for the map to not reload every time I return to the first page.

Or is bottom navigation not the best option for this use case?

1

There are 1 answers

0
DeKekem On

I have managed to fix it by using AutomaticKeepAliveClientMixin as explained in this post