StateProvider<T> class Null safety

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>((ref) => ProductsNotifier());

Widget build(BuildContext context, ScopedReader watch) {
  final List<Product> products = watch(productsProvider);
  final selectedProductId = watch(selectedProductIdProvider);

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


StateProvider(Create<T, ProviderReference> _create, {String? name})
A provider that expose a value which can be modified from outside. [...]


argument Object?
If this provider was created with the .family modifier, argument is variable used.
read-only, inherited
debugId String
A unique identifier for this provider, used by devtools to differentiate providers [...]
late, final, inherited
from Family<dynamic, dynamic, dynamic, ProviderReference, RootProvider>?
If this provider was created with the .family modifier, from is the .family instance.
read-only, inherited
hashCode int
The hash code for this object. [...]
@nonVirtual, read-only, inherited
name String?
A custom label for providers. [...]
final, inherited
notifier AlwaysAliveProviderBase<StateController<T>, StateController<T>>
Obtains the StateController associated with this provider, but without listening to it. [...]
late, final
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


create(ProviderReference ref) StateController<T>
createElement() ProviderElement<StateController<T>, StateController<T>>
An internal method that defines how a provider behaves.
createState() → _StateProviderState<T>
An internal method that creates the state of a provider.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
overrideWithProvider(AlwaysAliveProviderBase<Object?, StateController<T>> provider) → ProviderOverride
Overrides the behavior of this provider with another provider. [...]
overrideWithValue(StateController<T> value) Override
Overrides the behavior of a provider with a value. [...]
select<Selected>(Selected selector(StateController<T> value)) ProviderListenable<Selected>
Partially listen to a provider. [...]
toString() String
A string representation of this object. [...]


operator ==(Object other) bool
The equality operator. [...]


autoDispose → const AutoDisposeStateProviderBuilder
Marks the provider as automatically disposed when no-longer listened. [...]
const AutoDisposeStateProviderBuilder()
family → const StateProviderFamilyBuilder
A group of providers that builds their value from an external parameter. [...]
const StateProviderFamilyBuilder()