StateProvider<State> constructor

  1. Create<State, StateProviderRef<State>> create,
  2. {String? name,
  3. List<ProviderOrFamily>? dependencies,
  4. Family<dynamic, dynamic, ProviderBase>? from,
  5. Object? argument}

A provider that expose a value which can be modified from outside.

It can be useful for very simple states, like a filter or the currently selected item – which can then be combined with other providers or accessed in multiple screens.

The following code shows a list of products, and allows selecting a product by tapping on it.

final selectedProductIdProvider = StateProvider<String?>((ref) => null);
final productsProvider = StateNotifierProvider<ProductsNotifier, List<Product>>((ref) => ProductsNotifier());

Widget build(BuildContext context, WidgetRef ref) {
  final List<Product> products =;
  final selectedProductId =;

  return ListView(
    children: [
      for (final product in products)
          onTap: () => =,
          child: ProductItem(
            product: product,
            isSelected: selectedProductId.state ==,


  Create<State, StateProviderRef<State>> create, {
  String? name,
  List<ProviderOrFamily>? dependencies,
  Family? from,
  Object? argument,
})  : notifier = _NotifierProvider(
        name: modifierName(name, 'notifier'),
        dependencies: dependencies,
        from: from,
        argument: argument,
      super(name: name, from: from, argument: argument);