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(),
);
Methods
-
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 -
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