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
Mixed in types
Annotations
  • @sealed

Constructors

AutoDisposeBlocProvider(Create<B, AutoDisposeBlocProviderRef<B>> create, {String? name, List<ProviderOrFamily>? dependencies, Family<dynamic, dynamic, ProviderBase>? from, Object? argument})
Auto Dispose
AutoDisposeBlocProvider.scoped(String name)
Creates a BlocProvider that needs to be overridden

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
bloc AutoDisposeProviderBase<B>
Obtains the BlocBase associated with this AutoDisposeBlocProvider, without listening to it.
final
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<B>
Equivalent to bloc
no setter
originProvider ProviderBase<B>
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
stream AutoDisposeProviderBase<AsyncValue<S>>
BlocProvider.stream
latefinal

Methods

create(covariant AutoDisposeProviderElementBase<S> ref) → S
Initializes the state of a provider
override
createElement() AutoDisposeProviderElementBase<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
overrideWithProvider(AutoDisposeBlocProvider<B, S> value) Override
Overrides a provider with a value, ejecting the default behaviour.
inherited
overrideWithValue(B value) Override
Overrides a provider with a value, ejecting the default behaviour.
inherited
select<Selected>(Selected selector(S value)) ProviderListenable<Selected>
Partially listen to a provider.
inherited
toString() String
A string representation of this object.
inherited
updateShouldNotify(S previousState, S newState) bool
The bloc notifies when the state changes.
inherited

Operators

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

Constants

family → const AutoDisposeBlocProviderFamilyBuilder
A group of providers that builds their value from an external parameter.