AutoDisposeStateProvider<State> class
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 = ref.watch(productsProvider);
final selectedProductId = ref.watch(selectedProductIdProvider);
return ListView(
children: [
for (final product in products)
GestureDetector(
onTap: () => ref.read(selectedProductIdProvider.notifier).state = product.id,
child: ProductItem(
product: product,
isSelected: selectedProductId.state == product.id,
),
),
],
);
}
- Inheritance
-
- Object
- ProviderBase<
State> - AutoDisposeProviderBase<
State> - AutoDisposeStateProvider
- Available extensions
- Annotations
-
- @sealed
Constructors
-
AutoDisposeStateProvider(Create<
State, AutoDisposeStateProviderRef< create, {String? name, List<State> >ProviderOrFamily> ? dependencies, Family<dynamic, dynamic, ProviderBase> ? from, Object? argument}) - A provider that expose a value which can be modified from outside.
Properties
-
allTransitiveDependencies
→ List<
ProviderOrFamily> ? -
All the dependencies of a provider and their dependencies too.
latefinalinherited
- argument → Object?
-
If this provider was created with the
.family
modifier, argument is variable used.finalinherited -
dependencies
→ List<
ProviderOrFamily> ? -
The list of providers that this provider potentially depends on.
latefinalinherited
-
from
→ Family<
dynamic, dynamic, ProviderBase> ? -
If this provider was created with the
.family
modifier, from is the.family
instance.finalinherited - hashCode → int
-
The hash code for this object.
no setterinherited
- name → String?
-
A custom label for providers.
finalinherited
-
notifier
→ AutoDisposeProviderBase<
StateController< State> > -
Obtains the
StateController
associated with this provider, but without listening to it.final -
originProvider
→ ProviderBase<
StateController< State> > -
The provider that will be refreshed when calling ProviderContainer.refresh
and that will be overridden when passed to
ProviderScope
.no setterinherited - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
state
→ AutoDisposeProviderBase<
StateController< State> > -
Obtains the StateNotifier and also listens to the state, as opposed to
notifier which will not listen to the state.
latefinal
Methods
-
create(
covariant AutoDisposeProviderElementBase< State> ref) → State -
Initializes the state of a provider
override
-
createElement(
) → AutoDisposeStateProviderElement< State> -
An internal method that defines how a provider behaves.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
overrideWithProvider(
AutoDisposeStateProvider< State> value) → Override -
Overrides a provider with a value, ejecting the default behaviour.
inherited
-
overrideWithValue(
StateController< State> value) → Override -
Overrides a provider with a value, ejecting the default behaviour.
inherited
-
select<
Selected> (Selected selector(State value)) → ProviderListenable< Selected> -
Partially listen to a provider.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
updateShouldNotify(
State previousState, State newState) → bool -
Called when a provider is rebuilt. Used for providers to not notify their
listeners if the exposed value did not change.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- family → const AutoDisposeStateProviderFamilyBuilder
- A group of providers that builds their value from an external parameter.