How can I invalidate dependent providers? #3743
Unanswered
hisaichi5518
asked this question in
Q&A
Replies: 1 comment 1 reply
-
You coud transforn B in a NotifierProvider and add a refresh() method that invalidates A that would be called by your widget |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using Riverpod and have Provider A and Provider B. Provider B depends on Provider A. A Widget depends on Provider B, but the Widget doesn't know that Provider B depends on Provider A. When the Widget wants to recreate Provider B's data from scratch, it invalidates Provider B. However, since Provider B depends on Provider A, there's no change in the value.
To change the value, we need to invalidate providerA. However, I don't think the Widget should know the implementation detail of Provider B, which is "Provider B depends on Provider A". Is there a solution for this?
EDIT:
By using
ref.onDispose
to perform invalidation, we can encapsulate the invalidation of providerA within providerB. However, when multiple Providers use onDispose to invalidate providerA, it appears that the invalidation of providerA is executed multiple times.Beta Was this translation helpful? Give feedback.
All reactions