BaseCubit<T> class abstract

A Cubit for screens that load data of type T and run actions.

Every error from load and runAction goes through onError, so override it (calling super) to log or report errors.

Nothing is emitted after close, so late responses are harmless.

Constructors

BaseCubit([DataState<T>? initialState])
Creates the cubit, starting at initialState (default DataInitial).

Properties

buildState → BuildState<T>
The last state the screen rendered.
no setter
cache → SoftCache
In-memory cache used by load and observe.
final
data → T?
The data on screen, or null if not loaded.
no setter
hashCode → int
The hash code for this object.
no setterinherited
isClosed → bool
Whether the bloc is closed.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
state → DataState<T>
The current state.
no setterinherited
stream → Stream<DataState<T>>
The current stream of states.
no setterinherited

Methods

addError(Object error, [StackTrace? stackTrace]) → void
Reports an error which triggers onError with an optional StackTrace.
inherited
close() → Future<void>
Closes the instance. This method should be called when the instance is no longer needed. Once close is called, the instance can no longer be used.
emit(DataState<T> state) → void
Updates the state to the provided state. emit does nothing if the state being emitted is equal to the current state.
inherited
emitData(T data) → void
Shows data.
emitError(Object error, [StackTrace? stackTrace]) → void
Shows error.
emitLoading() → void
Shows DataLoading.
emitState(DataState<T> state) → void
Emits any state, including your own BuildState/ActionState subclasses. Cancels any load in flight when state is a BuildState, so a late response does not overwrite it.
load(Future<T> request(), {String? cacheKey, Duration? cacheTtl, bool forceRefresh = false, bool keepDataWhileLoading = false}) → Future<void>
Loads the screen's data with request.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
observe<R>(String tag, Future<R> request(), {String? cacheKey, Duration? cacheTtl, bool forceRefresh = false}) → DataObserver<R>
Loads request into the observer for tag and returns the observer.
observer<R>(String tag) → DataObserver<R>
Returns the observer for tag, creating it on first use.
onChange(Change<DataState<T>> change) → void
Called whenever a change occurs with the given change. A change occurs when a new state is emitted. onChange is called before the state of the cubit is updated. onChange is a great spot to add logging/analytics for a specific cubit.
inherited
onError(Object error, StackTrace stackTrace) → void
Called whenever an error occurs and notifies BlocObserver.onError.
inherited
runAction<R>(Future<R> action(), {void onSuccess(R result)?}) → Future<ActionResult<R>>
Runs a one-shot action and returns its ActionResult.
toString() → String
A string representation of this object.
inherited
updateData(T update(T current)) → void
Changes the data on screen without a request, e.g. to append an item or flip a flag after an action. Does nothing if no data is loaded.

Operators

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