BaseAsyncState<S extends Object?> class
abstract
Abstract base class for representing asynchronous state in a notifier or state management flow.
BaseAsyncState provides a common interface for handling loading, data, and error states in asynchronous operations, such as network requests or background computations.
S
is the type of data managed by the state.
This class is typically extended or implemented by concrete async state classes. It enables pattern matching via when and whenData, and provides utility constructors and methods for transitioning between loading, data, and error states.
- Implementers
Constructors
- BaseAsyncState.new({required AsyncStatus status, S? data, ErrorState? errorState})
-
Creates a BaseAsyncState with optional
data
anderrorState
.const - BaseAsyncState.data(S? data)
-
Creates a data state with the given
data
.const - BaseAsyncState.error(ErrorState? errorState)
-
Creates an error state with the given
errorState
.const - BaseAsyncState.loading()
-
Creates a loading state.
const
Properties
- data → S?
-
The data held by the state, if any.
final
- errorState → ErrorState?
-
The error information held by the state, if any.
final
- hasError → bool
-
Returns true if the state represents an error.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- isLoading → bool
-
Returns true if the state is loading.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toData(
S data) → AsyncState< S> -
Returns a new state with the given
data
. -
toError(
Object error, {String? message, StackTrace? stackTrace}) → AsyncState< S> -
Returns a new state representing an error with the given
error
. -
toLoading(
) → AsyncState< S> - Returns a new state representing the loading state.
-
toString(
) → String -
A string representation of this object.
inherited
-
when<
T> ({required T loading(), required T data(S data), required T error(ErrorState e)}) → T - Pattern matching for async state.
-
whenData<
T> (void data(S data), {void loading()?, void error(ErrorState e)?}) → void - Optional pattern matching for async state, focused on data extraction.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override