Loading...
Loading...
Use Riverpod family providers to pass parameters and cache per parameter; FutureProvider.family, NotifierProvider.family, autoDispose with family, overriding in tests. Use when fetching data by ID, pagination, or any provider that depends on a parameter. Use this skill when the user asks about family, provider parameters, or caching by ID.
npx skill4agent add serverpod/skills-registry riverpod-family.family(ref, param)final userProvider = FutureProvider.autoDispose.family<User, String>((ref, id) async {
final dio = Dio();
final response = await dio.get('https://api.example.com/users/$id');
return User.fromJson(response.data);
});userProvider(id)NotifierProvider.familyAsyncNotifierProvider.family.autoDispose.familyfinal userProvider = AsyncNotifierProvider.autoDispose.family<UserNotifier, User, String>(
UserNotifier.new,
);
class UserNotifier extends AsyncNotifier<User> {
UserNotifier(this.id);
final String id;
Future<User> build() async {
final dio = Dio();
final response = await dio.get('https://api.example.com/users/$id');
return User.fromJson(response.data);
}
}final user = ref.watch(userProvider('123'));
final other = ref.watch(userProvider('456')); // independent stateref.watch(myProvider([1,2,3]))[1,2,3] != [1,2,3]