StreamStatus<TState extends BlocState> class
abstract
Represents the current status of a bloc's state stream.
StreamStatus wraps state changes with metadata about the type of change:
- UpdatingStatus: Normal state transition (success)
- WaitingStatus: Async operation in progress (loading)
- CancelingStatus: Operation was cancelled
- FailureStatus: Operation failed with an error
Usage in Widgets
@override
Widget onBuild(BuildContext context, StreamStatus status) {
if (status is WaitingStatus) {
return CircularProgressIndicator();
}
if (status is FailureStatus) {
return Text('Error occurred');
}
return Text('Count: ${bloc.state.count}');
}
Pattern Matching
Use when for exhaustive pattern matching:
status.when(
updating: (state, oldState, event) => Text('$state'),
waiting: (state, oldState, event) => CircularProgressIndicator(),
failure: (state, oldState, event) => Text('Error'),
canceling: (state, oldState, event) => Text('Cancelled'),
);
Best Practices
- Use StreamStatus for transient UI states (loading, error feedback)
- Use BlocState for persistent application data
- Check status type before accessing state in UI
- Implementers
- Available extensions
- Annotations
Constructors
- StreamStatus(TState state, TState oldState, EventBase? event)
-
Creates a StreamStatus with the given state values and event.
const
- StreamStatus.canceling(TState state, TState oldState, EventBase? event)
-
Creates a CancelingStatus indicating an operation was cancelled.
factory
- StreamStatus.failure(TState state, TState oldState, EventBase? event, {Object? error, StackTrace? errorStackTrace})
-
Creates a FailureStatus indicating an operation failed.
factory
- StreamStatus.updating(TState state, TState oldState, EventBase? event)
-
Creates an UpdatingStatus indicating a successful state transition.
factory
- StreamStatus.waiting(TState state, TState oldState, EventBase? event)
-
Creates a WaitingStatus indicating an async operation in progress.
factory
Properties
- event → EventBase?
-
The event that triggered this status change, if any.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- oldState → TState
-
The previous state value before this status change.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → TState
-
The current state value.
final
Methods
-
copyWith(
{TState? state, TState? oldState, EventBase? event}) → StreamStatus< TState> - Creates a copy of this status with optionally overridden values.
-
isCancelingFor<
S extends BlocState> () → bool -
Available on StreamStatus<
Returns true if this is a CancelingStatus for the given state type.BlocState> , provided by the StatusChecks extension -
isFailureFor<
S extends BlocState> () → bool -
Available on StreamStatus<
Returns true if this is a FailureStatus for the given state type.BlocState> , provided by the StatusChecks extension -
isUpdatingFor<
S extends BlocState> () → bool -
Available on StreamStatus<
Returns true if this is an UpdatingStatus for the given state type.BlocState> , provided by the StatusChecks extension -
isWaitingFor<
S extends BlocState> () → bool -
Available on StreamStatus<
Returns true if this is a WaitingStatus for the given state type.BlocState> , provided by the StatusChecks extension -
match<
S extends BlocState, R> ({required R updating(UpdatingStatus< S> ), required R waiting(WaitingStatus<S> ), required R canceling(CancelingStatus<S> ), required R failure(FailureStatus<S> ), required R orElse(StreamStatus<BlocState> )?}) → R -
Available on StreamStatus<
Type-safe pattern matching with an optional fallback.BlocState> , provided by the StatusChecks extension -
matchesState<
S extends BlocState> () → bool -
Available on StreamStatus<
Returns true if this status is for the given state type.BlocState> , provided by the StatusChecks extension -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
tryCastToCanceling<
S extends BlocState> () → CancelingStatus< S> ? -
Available on StreamStatus<
Attempts to cast this to CancelingStatus for the given state type. Returns null if the cast is not valid.BlocState> , provided by the StatusChecks extension -
tryCastToFailure<
S extends BlocState> () → FailureStatus< S> ? -
Available on StreamStatus<
Attempts to cast this to FailureStatus for the given state type. Returns null if the cast is not valid.BlocState> , provided by the StatusChecks extension -
tryCastToUpdating<
S extends BlocState> () → UpdatingStatus< S> ? -
Available on StreamStatus<
Attempts to cast this to UpdatingStatus for the given state type. Returns null if the cast is not valid.BlocState> , provided by the StatusChecks extension -
tryCastToWaiting<
S extends BlocState> () → WaitingStatus< S> ? -
Available on StreamStatus<
Attempts to cast this to WaitingStatus for the given state type. Returns null if the cast is not valid.BlocState> , provided by the StatusChecks extension -
when<
R> ({required R updating(TState state, TState oldState, EventBase? event), required R waiting(TState state, TState oldState, EventBase? event), required R canceling(TState state, TState oldState, EventBase? event), required R failure(TState state, TState oldState, EventBase? event)}) → R - Pattern matches on the status type and executes the corresponding callback.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override