mapEventToState method
Maps the events to the corresponding state changes in the bloc.
This method handles events like patching values and calculating results. It is responsible for updating the state in response to events.
event
: The event to be handled by the bloc.
Implementation
@override
@protected
Stream<S> mapEventToState(FastCalculatorBlocEvent event) async* {
final eventType = event.type;
if (eventType == FastCalculatorBlocEventType.retrieveDefaultValues) {
defaultDocument = await retrieveDefaultCalculatorDocument();
defaultCalculatorState = await initializeDefaultCalculatorState();
} else if (eventType == FastCalculatorBlocEventType.saveEntryChanged) {
final saveUserEntry = await canSaveUserEntry();
if (saveUserEntry) {
await persistCalculatorDocument();
} else {
await clearCalculatorDocument(force: true);
}
} else {
yield* super.mapEventToState(event);
}
}