Sunil
Sunil

Reputation: 153

Flutter RiverPod StateProvider with auto dispose not disposing the updated value when navigate to next screen

I am using StateProvider with bool value false and update it to true on button Click and move to next screen and use same StateProvider on new screen but StateProvider contains the value as true instead of default value which is false.

final boolValueProvider = StateProvider.autoDispose<bool>((ref) => false);

Upvotes: 2

Views: 3138

Answers (1)

yomko
yomko

Reputation: 288

Flutter uses stack navigation, meaning that "moving" to the next screen just pushes another route onto the stack while the previous route is still there and "live". AFAIK, the Riverpod's autoDispose modifier disposes a provider only when the provider's value is not longer used, but in your case the value is still used by the previous route. So you should probably leave the screen (pop the route from the stack) and then re-enter it to see your provider actually disposed.

Upvotes: 4

Related Questions