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<FastAppFeaturesBlocState> mapEventToState(
FastAppFeaturesBlocEvent event,
) async* {
final payload = event.payload;
final type = event.type;
_logger.debug('Event received: $type');
if (type == FastAppFeaturesBlocEventType.init) {
yield* handleInitEvent();
} else if (type == FastAppFeaturesBlocEventType.initialized) {
if (payload is FastAppFeaturesBlocEventPayload) {
assert(payload.features != null);
yield* handleInitializedEvent(payload.features!);
}
} else if (isInitialized) {
switch (type) {
case FastAppFeaturesBlocEventType.retrieveFeatures:
yield* handleRetrieveFeaturesEvent();
case FastAppFeaturesBlocEventType.featuresRetrieved:
if (payload is FastAppFeaturesBlocEventPayload) {
assert(payload.features != null);
yield* handleFeaturesRetrievedEvent(payload.features!);
}
case FastAppFeaturesBlocEventType.enableFeature:
if (payload is FastAppFeaturesBlocEventPayload) {
assert(payload.feature != null);
yield* handleEnableFeaturesEvent([payload.feature!]);
}
case FastAppFeaturesBlocEventType.enableFeatures:
if (payload is FastAppFeaturesBlocEventPayload) {
assert(payload.features != null);
yield* handleEnableFeaturesEvent(payload.features!);
}
case FastAppFeaturesBlocEventType.disableFeature:
if (payload is FastAppFeaturesBlocEventPayload) {
assert(payload.feature != null);
yield* handleDisableFeaturesEvent([payload.feature!]);
}
case FastAppFeaturesBlocEventType.disableFeatures:
if (payload is FastAppFeaturesBlocEventPayload) {
assert(payload.features != null);
yield* handleDisableFeaturesEvent(payload.features!);
}
default:
assert(false, 'FastAppFeaturesBloc is not initialized yet.');
}
} else {
assert(false, 'FastAppFeaturesBloc is not initialized yet.');
}
}