mapEventToState method

Must be implemented when a class extends BidirectionalBloc. mapEventToState is called whenever an event is added and will convert that event into a new BloC state. It can yield zero, one or several states for an event.

Implementation

@override
Stream<FastConnectivityStatusBlocState> mapEventToState(
  FastConnectivityStatusBlocEvent event,
) async* {
  final eventType = event.type;
  final payload = event.payload;
  final isPayloadDefined = payload is FastConnectivityStatusBlocEventPayload;

  _logger.debug('Event type: $eventType received.');

  if (eventType == FastConnectivityStatusBlocEventType.init) {
    yield* handleInitEvent(payload);
  } else if (eventType ==
      FastConnectivityStatusBlocEventType.checkConnectivity) {
    yield* handleCheckConnectivityEvent();
  } else if (isPayloadDefined) {
    if (eventType == FastConnectivityStatusBlocEventType.initialized) {
      yield* handleInitializedEvent(payload);
    } else if (isInitialized) {
      if (eventType ==
          FastConnectivityStatusBlocEventType.connectivityStatusChanged) {
        yield handleConnectivityStatusChanged(payload);
      }
    }
  }
}