As the question implies, I am trying to create an AutoDisposeAsyncNotifierProviderFamily. I currently have this:
final participantProvider = AsyncNotifierProvider.autoDispose.family<
ParticipantNotifier,
Map<String, List<String>>,
String
>((ref, id) => ParticipantNotifier(id));
class ParticipantNotifier extends AsyncNotifier<Map<String, List<String>>> {
ParticipantNotifier(this.id);
final String id;
@override
FutureOr<Map<String, List<String>>> build() {
// Get some participants for this event's id
}
}
(extra indents and linebreaks added for readability). However, I get the error: The argument type 'ParticipantNotifier Function(dynamic, dynamic)' can't be assigned to the parameter type 'ParticipantNotifier Function()'
. I don’t get why the parameter has type ParticipantNotifier Function()
even if I add the family modifier. With some other simpler providers I successfully created Families with a similar syntax. Any help much appreciated!
2
Answers
I found the answer: the Notifier itself has to be defined as
So it needs to extend
AutoDisposeFamilyAsyncNotifier
Following OP’s answer (as well as this answer by Remi), we’ll also need to remove the constructor and add the input to the build method.
Here’s the full code for this example: