AutoDisposeBlocProvider<B extends BlocBase<S> , S> class
Auto Dispose
Marks the provider as automatically disposed when no-longer listened.
final counterProvider1 = BlocProvider.autoDispose((ref) => CounterCubit(0));
final counterProvider2 - AutoDisposeBlocProvider((ref) => CounterCubit(0));
The maintainState
property is a boolean (false
by default) that allows
the provider to tell Riverpod if the state of the provider should be
preserved even if no-longer listened.
final myProvider = BlocProvider.autoDispose((ref) {
final asyncValue = ref.watch(myFutureProvider);
final firstState = asyncValue.data!.value;
ref.maintainState = true;
return CounterBloc(firstState);
});
This way, if the asyncValue
has no data, the provider won't create
correctly the state and if the UI leaves the screen and re-enters it,
the asyncValue
will be readed again to retry creating the state.
- Annotations
-
- @sealed
Constructors
-
AutoDisposeBlocProvider(Create<
B, AutoDisposeProviderReference> create, {String? name}) - BlocProvider
Properties
- argument → Object?
-
If this provider was created with the
.family
modifier, argument is variable used.no setterinherited - debugId ↔ String
-
A unique identifier for this provider, used by devtools to differentiate providers
latefinalinherited
-
from
→ Family<
dynamic, dynamic, dynamic, ProviderReference, RootProvider> ? -
If this provider was created with the
.family
modifier, from is the.family
instance.no setterinherited - hashCode → int
-
The hash code for this object.
no setterinherited
- name → String?
-
A custom label for providers.
finalinherited
-
notifier
→ AutoDisposeProviderBase<
B, B> -
BlocProvider.notifier
latefinal - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
stream
→ AutoDisposeProviderBase<
Stream< S> , AsyncValue<S> > -
BlocProvider.stream
latefinal
Methods
-
create(
covariant AutoDisposeProviderReference ref) → B -
createElement(
) → AutoDisposeProviderElement< B, S> -
An internal method that defines how a provider behaves.
inherited
-
createState(
) → ProviderStateBase< B, S> -
An internal method that creates the state of a provider.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
overrideWithProvider(
AutoDisposeBlocProvider< B, S> provider) → ProviderOverride -
BlocProvider.overrideWithProvider
-
overrideWithValue(
B value) → ProviderOverride -
BlocProvider.overrideWithValue
inherited -
select<
Selected> (Selected selector(S value)) → ProviderListenable< Selected> -
Partially listen to a provider.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited