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<FastRewardedAdBlocState> mapEventToState(
FastRewardedAdBlocEvent event,
) async* {
final type = event.type;
final payload = event.payload;
_logger.debug('Event received: $type');
if (type == FastRewardedAdBlocEventType.init) {
if (payload is FastRewardedAdBlocEventPayload) {
yield* handleInitEvent(payload);
}
} else if (type == FastRewardedAdBlocEventType.initalized) {
yield* handleInitializedEvent();
} else if (isInitialized) {
if (type == FastRewardedAdBlocEventType.loadAndShowAd) {
yield* handleLoadAndShowAd();
} else if (type == FastRewardedAdBlocEventType.adLoaded) {
yield* handleAdLoaded();
} else if (type == FastRewardedAdBlocEventType.adShowed) {
yield* handleAdShowed();
} else if (type == FastRewardedAdBlocEventType.earnedReward) {
if (payload is FastRewardedAdBlocEventPayload) {
yield* handleEarnedReward(payload);
}
} else if (type == FastRewardedAdBlocEventType.adDismissed) {
yield* handleAdDismissed();
} else if (type == FastRewardedAdBlocEventType.adLoadingError ||
type == FastRewardedAdBlocEventType.adShowingError) {
if (payload is FastRewardedAdBlocEventPayload) {
yield* handleAdError(payload);
}
} else if (type == FastRewardedAdBlocEventType.clearAndCancelAdRequest) {
yield* handleClearAndCancelAdRequest();
}
} else {
assert(false, 'FastRewardedAdBloc is not initialized yet.');
}
}