mapEventToState method
@Deprecated - Use on
Must be implemented when a class extends Bloc
.
mapEventToState is called whenever an event
is added
and is responsible for converting that event
into a new state.
mapEventToState can yield
zero, one, or multiple states for an event.
Implementation
@override
Stream<ResetPasswordState> mapEventToState(
ResetPasswordEvent event,
) async* {
if (event is ResetPasswordButtonTapEvent) {
yield ResetPasswordLoading();
final response =
await controller.resetPasswordByPhone(phone: event.phone);
if (response.ok) {
yield ResetPasswordLoadSuccess(response);
return;
}
yield ResetPasswordLoadFailure(
errorMessage: response.message ?? 'An unknown error occurred.');
}
if (event is ResetPasswordEmailButtonTapEvent) {
yield ResetPasswordLoading();
final response =
await controller.resetPasswordByEmail(model: event.model);
if (response.ok) {
yield ResetPasswordLoadSuccess(response);
return;
}
yield ResetPasswordLoadFailure(
errorMessage: response.message ?? 'An unknown error occurred.');
}
}