Avoiding disposing when StateNotifierProvider gets invalidated #2325
andreasgangso
started this conversation in
General
Replies: 1 comment 2 replies
-
@rrousselGit I ended up overriding dispose() in my package: player_state_notifier.dart Would creating a PR as I described be useful/accepted? I don't want to waste either your time or mine. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Use case: i want to have StateNotifiers which are not controlled by riverpod, but I want to use riverpod's StateNotifierProvider for easy state access.
However, this isn't easy because riverpod is disposing the notifiers on this line which is run when the provider is invalidated.
To help such use cases, I'm wondering if it's a good idea to submit a PR which gives StateNotifierProvider() an argument to prevent the notifier from being disposed. Alternatively, I could override dispose() on the StateNotifier.
But I'm worried that future StateNotifierProvider changes could mess up the StateNotifier in other ways.
Anyone got any thoughts on this?
Here's concrete code showing my setup.
Beta Was this translation helpful? Give feedback.
All reactions