Reputation: 119
In my GoRouter
, I retrieve the query params from the URL:
builder: (context, state) {
String q = state.queryParams['q'] ?? '';
int pageNumberInt = int.tryParse(state.queryParams['page'] ?? '1') ?? 1;
// Return component...
}
I would like, before returning the Widget, to update the state of a provider but how do I get access to "ref" to do something like:
ref.watch(searchFieldValueProvider.notifier).update((state) => q)
Upvotes: 2
Views: 771
Reputation: 4824
In any case, you need to have access to Ref
in order to update the provider status. You can pass it as an argument or in a class constructor. It all depends on your architecture.
And, it will be ref.read(...)
or ref.refresh(...)
(if we just need to reset the state) that will need to be used.
Upvotes: 1