Flutter & Riverpod | How to Maintain the state of NavigationBar across tabs

01kg

01kg

Posted on October 8, 2024

Flutter & Riverpod | How to Maintain the state of NavigationBar across tabs

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.

💖 💪 🙅 🚩
01kg
01kg

Posted on October 8, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024