Closed samandmoore closed 4 years ago
There is a ref.container.refresh(provider);
There is a
ref.container.refresh(provider);
@smiLLe oh jeeze 🤦🏻 I dunno how I missed that. thank you.
I guess then my questions are slightly different:
ref.container.refresh(...)
? is ref.container
likely to remain public API?Yes that's fine.
Awesome. Thanks a lot. And thanks for the library 😄
Is your feature request related to a problem? Please describe. I'm working on an app that uses riverpod and I'm finding that it's annoying and limiting that the only place where I can mark a
Provider
as needing to be refreshed / triggering it to be refreshed is from within the widget tree. In other words, I have to be somewhere that has aBuildContext
in scope so that I can docontext.refresh(someProvider)
.For context, I'm building an app for storing recipes. One of the things you can do is delete a recipe. I am managing the lifecycle of deleting a recipe with a
StateNotifier
calledDeleteRecipeNotifier
. The notifier is pretty trivial. It roughly looks like this:This is paired with some UI for showing a bottom sheet with a confirm button and a loading indicator while the delete is happening. When the delete is successful, the bottom sheet is closed and the UI pops back to a different screen.
(forgive me for blending hooks and non-hooks here 😄 i'm exploring some different approaches)
Describe the solution you'd like What I'd love to be able to do is trigger a refresh of the
recipesProvider
from within myDeleteRecipeNotifier
. Either by constructing it with aProviderReference
or passing in a lambda likerefreshRecipes: () => ref.refresh(recipesProvider)
to keepProviderReference
out of the notifier.Describe alternatives you've considered Alternatively, I can keep doing what I'm doing in the example code above: listen to the notifier and trigger a refresh from the widget tree. If you've got a strong reason why I should prefer this approach, I'd love to hear more! I'm sure you have a philosophy around how this stuff should be done. I'm open to all sorts of ideas, and I totally accept that I might be thinking about this wrong.
Thanks!