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<FastAppLoaderBlocState> mapEventToState(
FastAppLoaderBlocEvent event,
) async* {
final eventPayload = event.payload;
final eventType = event.type;
if (eventType == FastAppLoaderBlocEventType.init &&
!isInitialized &&
!isInitializing) {
var jobs = eventPayload!.jobs;
var errorReporter = eventPayload.errorReporter;
isInitializing = true;
yield currentState.copyWith(isLoading: isInitializing);
if (jobs != null && jobs.isNotEmpty) {
yield* _runJobs(
eventPayload.context!,
jobs,
errorReporter: errorReporter,
);
} else {
addEvent(const FastAppLoaderBlocEvent.initialized());
}
} else if (eventType == FastAppLoaderBlocEventType.initialized &&
!isInitialized &&
isInitializing) {
isInitialized = true;
yield currentState.copyWith(
isLoading: isInitializing,
isLoaded: isInitialized,
);
} else if (eventType == FastAppLoaderBlocEventType.initFailed) {
isInitializing = false;
isInitialized = false;
yield currentState.copyWith(
error: eventPayload!.error,
isLoading: isInitializing,
isLoaded: isInitialized,
progress: 0,
);
}
}