Ref.watch in Consumer does not trigger the creation of a new instance of provider #3839
Unanswered
abdullahrs
asked this question in
Q&A
Replies: 1 comment 2 replies
-
My guess is that your SocialCounts widget was unmounted while methods like |
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
-
Hi everybody,
I have a structure where every page has a provider (view model). I define provider with autoDispose on less used screens so that it does not take up active space in memory and state refreshes every create thats also plus for me.
Definition of my provider like below
The related UI part:
If I simply want to rebuild the relevant part when changes occur, I can remove the top-level watch from the build method ('Watch-1') and add a Consumer to the code, watching the value within it ('Watch-2'). However, I encounter the error 'Provider was used after being disposed' when I navigate to the screen. This error persists even when I attempt to access the Provider in initState (after a delay to ensure the context is mounted) or within any notifyListeners method. It basically not creates the provider if the watch inside the consumer.
You can say you could simply use a top-level watch at the beginning of the build method, but I'm curious if there's a more efficient or correct approach or simply am i using watch wrong ?
Beta Was this translation helpful? Give feedback.
All reactions