How to temporarily pause a provider or temporarily stop listening? #3741
-
Hello everyone, I have Widget A that uses a provider to listen to and update its state. When I push a new screen that contains Widget B, both widgets share the same provider. After I pop the screen with Widget B, I want Widget A to retain its previous state, the one it had before Widget B was pushed, instead of its state being changed by Widget B. Is there a way to temporarily pause or manage the state listening of a provider in this scenario? I’d really appreciate any help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There is ref.listenManual that returns a subscrpition. You could unsubscribe when B is pushed and listen again when B is popped. But there probably is some problem with your design here: A and B probably shouldn't update the same state if you don't want A to update when the state is changed. The goal of providers is to have things to react to their changes. |
Beta Was this translation helpful? Give feedback.
There is ref.listenManual that returns a subscrpition. You could unsubscribe when B is pushed and listen again when B is popped.
But there probably is some problem with your design here: A and B probably shouldn't update the same state if you don't want A to update when the state is changed. The goal of providers is to have things to react to their changes.