onError method

  1. @mustCallSuper
void onError(
  1. Object error,
  2. StackTrace stackTrace

Called whenever an error is thrown within mapEventToState. By default all errors will be ignored and bloc functionality will be unaffected. The stackTrace argument may be null if the state stream received an error without a stackTrace. A great spot to handle errors at the individual Bloc level.

Note: super.onError should always be called last.

void onError(Object error, StackTrace stackTrace) {
  // Custom onError logic goes here

  // Always call super.onError with the current error and stackTrace
  super.onError(error, stackTrace);


void onError(Object error, StackTrace stackTrace) {
  BlocSupervisor.delegate.onError(this, error, stackTrace);
  assert(() {
    throw BlocUnhandledErrorException(this, error, stackTrace);