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.
- Inheritance
-
- Object
- ProviderOrFamily
- ProviderBase<
S> - AutoDisposeBlocProvider
- Available Extensions
Constructors
-
AutoDisposeBlocProvider(B _createFn(AutoDisposeBlocProviderRef<
B, S> ref), {String? name, Iterable<ProviderOrFamily> ? dependencies, @Deprecated('Will be removed in 3.0.0') Family<Object?> ? from, @Deprecated('Will be removed in 3.0.0') Object? argument, @Deprecated('Will be removed in 3.0.0') DebugGetCreateSourceHash? debugGetCreateSourceHash}) - Creates a StateNotifier and exposes its current state.
-
AutoDisposeBlocProvider.internal(B _createFn(AutoDisposeBlocProviderRef<
B, S> ref), {required String? name, required Iterable<ProviderOrFamily> ? dependencies, required Iterable<ProviderOrFamily> ? allTransitiveDependencies, required DebugGetCreateSourceHash? debugGetCreateSourceHash, Family<Object?> ? from, Object? argument}) - An implementation detail of Riverpod
- AutoDisposeBlocProvider.scoped(String name)
- Creates a BlocProvider that needs to be overridden
Properties
-
allTransitiveDependencies
→ Iterable<
ProviderOrFamily> ? -
All the dependencies of a provider and their dependencies too.
finalinherited
- argument → Object?
-
If this provider was created with the
.family
modifier, argument is the variable that was used.finalinherited -
bloc
→ Refreshable<
B> -
Obtains the Bloc associated with this provider, without listening
to state changes.
latefinal
- debugGetCreateSourceHash → DebugGetCreateSourceHash?
-
A debug-only fucntion for obtaining a hash of the source code of the
initialization function.
finalinherited
-
dependencies
→ Iterable<
ProviderOrFamily> ? -
The list of providers that this provider potentially depends on.
finalinherited
-
from
→ Family<
Object?> ? -
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
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addListener(
Node node, void listener(S? previous, S next), {required void onError(Object error, StackTrace stackTrace)?, required void onDependencyMayHaveChanged()?, required bool fireImmediately}) → ProviderSubscription< S> -
Starts listening to this transformer
inherited
-
createElement(
) → AutoDisposeBlocProviderElement< B, S> -
An internal method that defines how a provider behaves.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
overrideWith(
Create< B, AutoDisposeBlocProviderRef< create) → OverrideB, S> > -
read(
Node node) → S -
Obtains the result of this provider expression without adding listener.
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
Constants
-
family
→ const AutoDisposeStateNotifierProviderFamily<
NotifierT, T, Arg> Function<NotifierT extends StateNotifier< T> , T, Arg>(NotifierT _createFn(AutoDisposeStateNotifierProviderRef<NotifierT, T> ref, Arg arg), {Iterable<ProviderOrFamily> ? dependencies, String? name}) - A group of providers that builds their value from an external parameter.