mapEventToState method

  1. @override
Stream<FastSplashAdBlocState> mapEventToState(
  1. FastSplashAdBlocEvent event
)
override

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<FastSplashAdBlocState> mapEventToState(
  FastSplashAdBlocEvent event,
) async* {
  final payload = event.payload;
  final type = event.type;

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

  if (type == FastSplashAdBlocEventType.init) {
    yield* handleInitEvent(payload);
  } else if (type == FastSplashAdBlocEventType.initialized) {
    yield* handleInitializedEvent(payload);
  } else if (isInitialized) {
    if (type == FastSplashAdBlocEventType.loadAd) {
      yield* handleLoadSplashAdEvent();
    } else if (type == FastSplashAdBlocEventType.showAd) {
      yield* handleShowSplashAdEvent();
    } else if (type == FastSplashAdBlocEventType.adImpression) {
      if (payload is FastSplashAdBlocEventPayload) {
        yield* handleAdImpressionEvent(payload);
      }
    }
  }
}