StatusChecks<T extends BlocState> extension

Extension methods for type-safe status checking and casting.

These methods provide safe ways to check and cast StreamStatus instances to specific types without manual type checking.

Type Checking

if (status.isWaitingFor<MyState>()) {
  // Show loading indicator
}

Safe Casting

final updating = status.tryCastToUpdating<MyState>();
if (updating != null) {
  // Work with UpdatingStatus<MyState>
}

Pattern Matching

final result = status.match<MyState, Widget>(
  updating: (s) => Text(s.state.data),
  waiting: (s) => CircularProgressIndicator(),
  canceling: (s) => Text('Cancelled'),
  failure: (s) => Text('Error'),
  orElse: (s) => SizedBox.shrink(),
);
on

Methods

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.
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.