1

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);
Sunil
  • 143
  • 1
  • 2
  • 11
  • The literature is rushing to catch up with Remi's prolific development. In brief, avoid legacy ChangeNotifier, StateNotifier (and their providers) and StateProvider. Use only Provider, FutureProvider, StreamProvider, and Notifier, AsyncNotifier, StreamNotifier (and their providers). – Randal Schwartz Aug 21 '23 at 15:36

1 Answers1

2

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.

yomko
  • 248
  • 2
  • 7
  • if i pop previous screen before moving to next screen then on backpress it exit me from the application. Is there other solution so that i can use same Stateprovider on different screens. – Sunil Aug 22 '23 at 05:41
  • @Sunil Not sure that I understand your intention. You are already using the same provider on different screens. If you do need to forcefully reset its value on specific screen where autoDispose is not helpful, try to do it your way (e.g. inside a custom NavigatorObserver or using widgets like WillPopScope). – yomko Aug 22 '23 at 09:52