addHandler<TEvent extends BlocEvent> method

void addHandler<TEvent extends BlocEvent>(
  1. Future<T> handler(
    1. T getState(),
    2. TEvent event,
    3. void updateState(
      1. T
      ),
    4. Object? pageScope,
    )
)

Add an async Bloc event handler. getState gets the current Bloc state. Because this function is async, the the state may change between async calls. The event is the event that was sent to the Bloc. updateState is a function that updates the Bloc state. Call this to set state on things like progress indicators in a long running process. pageScope is an optional object that can be used for the lifetime of the page.

Implementation

void addHandler<TEvent extends BlocEvent>(
  Future<T> Function(
    T Function() getState,
    TEvent event,
    void Function(T) updateState,
    Object? pageScope,
  )
      handler,
) =>
    _handlersByEvent.putIfAbsent(
      TEvent,
      () => (getState, event, updateState, pageScope) =>
          handler(getState, event as TEvent, updateState, pageScope),
    );