📢 Beta Documentation – This documentation and plugin are under active development. The plugin is live and ready to explore, but docs are in beta. Final release coming in May 2026. Please explore, test, and share feedback!

Family Modifiers

Parameterized dependencies made simple with Riverpod Generator's automatic family support.

In classic Riverpod, you use `.family` to pass parameters into providers. With Riverpod Generator, you simply add arguments to your function or build method. The generator automatically handles the complex `family` typing for you.

Functional Families

Pass extra arguments natively to functions:

import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'user_profile.g.dart';

@riverpod
Future<User> userProfile(UserProfileRef ref, int userId) async {
  return ref.watch(apiClientProvider).getUser(userId);
}

Notifier Families

Families work identically with class-based logic by passing parameters into the build method:

@riverpod
class ProductDetails extends _$ProductDetails {
  @override
  FutureOr<Product> build(String productId) async {
    return ref.watch(productRepositoryProvider).fetchProduct(productId);
  }

  Future<void> updateStock(int newAmount) async {
    // Note: productId is implicitly available as a class field!
    await ref.read(apiClientProvider).updateStock(productId, newAmount);
    // Refresh the specific family member
    ref.invalidateSelf();
  }
}

Using Families in Widgets

Simply call the provider like a regular Dart function:

class ProductPage extends ConsumerWidget {
  final String id;

  const ProductPage({required this.id});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    // Pass the parameter smoothly
    final productAsync = ref.watch(productDetailsProvider(id));

    return productAsync.when(
      data: (product) => Text(product.name),
      loading: () => CircularProgressIndicator(),
      error: (e, st) => Text('Error: $e'),
    );
  }
}