When a provider [autoDispose] is destroy? #3099
Unanswered
quangson91
asked this question in
Q&A
Replies: 2 comments
-
That's expected. Navigating takes time and during that time your provider is disposed. Instead of calling |
Beta Was this translation helpful? Give feedback.
0 replies
-
Please check this.. You shouldn't call init(). the provider needs to initialize itself as the documentation recommends. Your case makes sense to me since you are not watching/listening to the provider on screen A. So it would make sense if it is being disposed right after you call the init() since it's not being used. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I already read the docs: https://riverpod.dev/docs/concepts/provider_lifecycles
which says that when provider is no longer used -> the autodispose provider will be destroy.
But I am still confuse.
Here is example:
Given:
myProvider
which is an autodispose provider.Now I have two screen A, B;
When user click an button from screen A -> I want to init
ref.read(myProvider).init()
then open screen B.My expectation is
myProvider
will live along with screenB
.The problem need to be clear:
If in screen
B
I do not call/usemyProvider
(eg: ref.listen, ref.watch myProvider) => Is thatmyProvider
still alive ?if in the
build()
of screenB
I callref.listen(myProvider)
=> It seemsmyProvider
will be alive along with screenB
, right ?But, I am not sure the instance of
myProvider
when we callref.read(myProvider).init()
& the provider here are the same ?I mean, is there anycase that the lifecycle of
myProvider
looks like:If there anything unclear, please tell me.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions