How to use single FAMILY PROVIDER for multiple widgets? Using family provider without passing data? #3488
phamquoctrongnta
started this conversation in
General
Replies: 2 comments
-
I have the same question. I am currently passing the provider from A to B, C and D by constructor parameter. |
Beta Was this translation helpful? Give feedback.
0 replies
-
An alternative would be storing the family parameter with a provider. @riverpod
Future<Foo> foo(FooRef ref, {required int id}) async {
/* fetch foo with id */
return ...
} We could do @riverpod
class SelectedFooId extends _$SelectedFooId {
@override
int build() => 1;
void update(int id) => state = id;
}
@riverpod
Future<Foo> foo(FooRef ref) async {
final selectedFooId = ref.watch(selectedFooIdProvider);
/* fetch foo with id */
return ...
} The documentation here explained combining providers with the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Sorry for my bad English.
Assume, I have screen
A
includeB
,C
andD
widgets.Widget tree:
A (parent)
--- B (child)
--- C (child)
--- D (child)
And I have a provider (with family):
I would like initialize
myAsyncNotifier
in screenA
.B
,C
andD
just need using it.In
A
:My problem is how to use myAsyncNotifierProvider without passing data in
B
,C
andD
? Because all of them just using, not need initialize.Beta Was this translation helpful? Give feedback.
All reactions