onEvent method

  1. @override
  2. @protected
  3. @mustCallSuper
void onEvent(
  1. Event event
)

Called whenever an event is added to the Bloc. A great spot to add logging/analytics at the individual Bloc level.

Note: super.onEvent should always be called first.

@override
void onEvent(Event event) {
  // Always call super.onEvent with the current event
  super.onEvent(event);

  // Custom onEvent logic goes here
}

See also:

  • BlocObserver.onEvent for observing events globally.

Implementation

@override
@protected
@mustCallSuper
void onEvent(Event event) {
  super.onEvent(event);
  if (logEvents && (logFilter?.call(event) ?? true)) {
    logger?.v(
      customLogOutput?.call(event) ?? event,
    );
  }
  if (!_eventStreamController.isClosed) {
    _eventStreamController.add(event);
  }
}