New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manually dispose provider #1295
Comments
Is ref.invalidate what you're looking for? |
I am sorry, I can't seem to find a method ref.invalidate. I'm using flutter_riverpod 1.0.3. Am I missing something obvious here? |
Oh, now I see you have it planned for 2.0.0. It looks great, this would solve my issue perfectly, I'm looking forward to it. |
The feature is already available in a dev release, so you can use it today. |
I am sorry to keep bothering you but now I am using ver 2.0.0-dev.5 and invalidate doesn't behave the way I would expect. The documentation says: "next read or next frame" is not clear to me. I would expect that if the provider doesn't have any active listeners, it will not be refreshed on the next frame, but wait until a new listener calls read or watch. Instead I am getting exactly the same behavior as refresh: all providers are recomputed immediately. Am I correct to assume that the intended behavior is for the provider to wait for an active listener before it refreshes? Also, is there a way to debug to see if a provider currently has any active listeners? |
That's the case Chances are you do have an active listener
Not really. There's a devtool planned though |
Closing as ref.invalidate should take care of this. |
How can we invalidate a provider in a StatefulWidget's |
@arreshashikant You should not use |
May I know how to clear an async provider or we should create a method in all the async providers and update the state to a blank or null sate? |
Is your feature request related to a problem? Please describe.
In my app, I have a lot of providers that make relatively expensive API calls to compute their state. The app has many different pages, and the first time each page is entered, the API call is made to get the data and then kept so it doesn't have to be remade next time the user enters the same page (the providers are NOT auto-dispose).
There are some events that can happen that require me to remake all calls, to update the info shown. The problem is that if I do ref.refresh() for all providers when this event happens, all API calls for the providers refreshed will be remade simultaneously, causing each to take way longer. Ideally, all current state of the providers should be invalidated, and then remade when the user navigates to each of the pages again.
Describe the solution you'd like
A way to call ref.dispose() on the providers that have invalidated state, so the state is only recomputed when needed, not immediately.
Describe alternatives you've considered
Somehow getting the container and manually disposing the providers. This would be very hacky and I don't really know how to do it.
The text was updated successfully, but these errors were encountered: