Replies: 3 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.
-
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.
-
This is a common situation. I want to solve it by passing provider as a parameter to child widget. But I found that AsyncNotifierProvider that with some arguments is not based AsyncNotifierProvider . I did not get the correct base class. I set the parameter type to AutoDisposeAsyncNotifierProvider is OK to AsyncNotifierProvider that without any arguments. But not work when I add some arguments to the provider. The error is
@rrousselGit Any suggestions for us? |
Beta Was this translation helpful? Give feedback.
-
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