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:

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<BlocState>, provided by the StatusChecks extension

Returns true if this is a CancelingStatus for the given state type.
isFailureFor<S extends BlocState>() bool

Available on StreamStatus<BlocState>, provided by the StatusChecks extension

Returns true if this is a FailureStatus for the given state type.
isUpdatingFor<S extends BlocState>() bool

Available on StreamStatus<BlocState>, provided by the StatusChecks extension

Returns true if this is an UpdatingStatus for the given state type.
isWaitingFor<S extends BlocState>() bool

Available on StreamStatus<BlocState>, provided by the StatusChecks extension

Returns true if this is a WaitingStatus for the given state type.
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<BlocState>, provided by the StatusChecks extension

Type-safe pattern matching with an optional fallback.
matchesState<S extends BlocState>() bool

Available on StreamStatus<BlocState>, provided by the StatusChecks extension

Returns true if this status is for the given state type.
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<BlocState>, provided by the StatusChecks extension

Attempts to cast this to CancelingStatus for the given state type. Returns null if the cast is not valid.
tryCastToFailure<S extends BlocState>() FailureStatus<S>?

Available on StreamStatus<BlocState>, provided by the StatusChecks extension

Attempts to cast this to FailureStatus for the given state type. Returns null if the cast is not valid.
tryCastToUpdating<S extends BlocState>() UpdatingStatus<S>?

Available on StreamStatus<BlocState>, provided by the StatusChecks extension

Attempts to cast this to UpdatingStatus for the given state type. Returns null if the cast is not valid.
tryCastToWaiting<S extends BlocState>() WaitingStatus<S>?

Available on StreamStatus<BlocState>, provided by the StatusChecks extension

Attempts to cast this to WaitingStatus for the given state type. Returns null if the cast is not valid.
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