mapEventToState method

  1. @override
Stream<FastAdInfoBlocState> mapEventToState(
  1. FastAdInfoBlocEvent 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<FastAdInfoBlocState> mapEventToState(
  FastAdInfoBlocEvent event,
) async* {
  final payload = event.payload;
  final type = event.type;

  if (type == FastAdInfoBlocEventType.init) {
    yield* handleInitEvent(payload?.adInfo);
  } else if (type == FastAdInfoBlocEventType.initialized) {
    yield* handleInitializedEvent(payload?.adInfo);
  } else if (isInitialized) {
    if (type == FastAdInfoBlocEventType.askForConsent) {
      yield* handleAskForConsentEvent();
    } else if (type == FastAdInfoBlocEventType.constentStatusChanged) {
      yield* handleConsentStatusChangedEvent(payload?.consentStatus);
    } else if (type == FastAdInfoBlocEventType.askForConsentIfNeeded) {
      yield* handleAskForConsentEventIfNeeded();
    } else {
      assert(false, 'Unknown event type: $type');
    }
  } else {
    assert(false, 'FastAdInfoBloc is not initialized yet.');
  }
}