Replies: 2 comments 4 replies
-
That's anti pattern. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Ok, If I wanted to change a provider's state in |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I am just getting started with riverpod
I have a StateNotifierProvider.
I want to interact with my StateNotifierProvider from "non-gui" parts of the app (
WidgetsBinding.instance!.addPostFrameCallback((_) {}
)In your example code I discovered this:
final providerContainer = ProviderContainer();
Using the above I was able to "trigger" a function inside my StateNotifierProvider without a Consumer widget.
BUT... it appears that using both ProviderScope and ProviderContainer(); creates 2 separate instances of my provider.
Best to show the full example code, to give this some reference:
If I alternately press each of my buttons 3 times a get the following debug lines:
So I clearly have 2 separate instances of my StateNotifierProvider, each with it's own state.
I can interact with either instance using
.read(indexProvider.notifier).add(5);
But I can not use
providerContainer.watch
Anyhow, do you have a pointer for me on how to get a Consumer widget to monitor
providerContainer
?Beta Was this translation helpful? Give feedback.
All reactions