Flutter & Riverpod | How to Maintain the state of NavigationBar across tabs
01kg
Posted on October 8, 2024
I created a NavigationBar, 4 tabs, each one ref.watch()
related provider. (Each provider basically fetches data from Database)
Riverpod caches provider state by default. But I found each time I tap a tab, the related provider would fetch again from DB.
According to Riverpod's doc:
If the UI stops using this provider, the cache will be destroyed. Then, if the UI ever uses the provider again, that a new network request will be made.
This indicates than the UI stops using the provider after another tab is tapped.
According to this Q&A answered by Remi Rousselet, the author of Riverpod:
You can use AutomaticKeepAliveClientMixin/IndexedStack if you want. Riverpod is unrelated to this
IndexedStack helped me.
Posted on October 8, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.