AsyncState<T> class
sealed
============================================================================
ASYNC STATE<T> - PURE DART ASYNC STATE REPRESENTATION
A sealed class representing the state of an async operation.
This is a pure Dart alternative to Flutter's AsyncSnapshot, enabling
business logic to remain framework-agnostic.
Pattern Matching (Dart 3.0+)
final state = asyncSignal.state;
switch (state) {
case AsyncLoading():
return CircularProgressIndicator();
case AsyncData(:final value):
return Text('Data: $value');
case AsyncError(:final error):
return Text('Error: $error');
}
- Implementers
Properties
- dataOrNull → T?
-
The data value, or null if not in data state.
no setter
- errorOrNull → Object?
-
The error, or null if not in error state.
no setter
- hasData → bool
-
Whether this state has data.
no setter
- hasError → bool
-
Whether this state has an error.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isLoading → bool
-
Whether this state represents loading.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stackTraceOrNull → StackTrace?
-
The stack trace, or null if not in error state.
no setter
Methods
-
maybeWhen<
R> ({R loading()?, R data(T value)?, R onError(Object error, StackTrace? stackTrace)?, required R orElse()}) → R - Maps this state with optional fallback for unhandled states.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
when<
R> ({required R loading(), required R data(T value), required R onError(Object error, StackTrace? stackTrace)}) → R - Maps this state to a value using the provided callbacks.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited