Provider<T extends Object> class

A Provider that manages the lifecycle of the value it provides by delegating to a pair of _createValue and _disposeValue.

It is usually used to avoid making a StatefulWidget for something trivial, such as instantiating a BLoC.

Provider is the equivalent of a State.initState combined with State.dispose. _createValue is called only once in State.initState. The create callback is lazily called. It is called the first time the value is read, instead of the first time Provider is inserted in the widget tree. This behavior can be disabled by passing _lazy false.

Inheritance
Annotations

Constructors

Provider(CreateProviderValueFn<T> create, {DisposeProviderValueFn<T>? dispose, bool? lazy})
A Provider that manages the lifecycle of the value it provides by delegating to a pair of _createValue and _disposeValue.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

maybeOf(BuildContext context) → T?
Injects the value held by a provider. In case the provider is not found, it returns null.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
of(BuildContext context) → T
Injects the value held by a provider. In case the provider is not found, it throws a ProviderWithoutScopeError.
overrideWithValue(T value) ProviderOverride<T>
It creates an override of this provider to be passed to ProviderScopeOverride.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

withArgument<T extends Object, A>(CreateArgProviderValueFn<T, A> create, {DisposeProviderValueFn<T>? dispose, bool lazy = true}) ArgProvider<T, A>