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<SocialState> mapEventToState(
SocialEvent event,
) async* {
if (event is SocialLoginTapEvent) {
yield SocialStateLoading();
switch (event.socialType) {
case SocialType.Facebook:
socialModel = await socialAuthRepository.facebookLogin();
break;
case SocialType.Google:
socialModel = await socialAuthRepository.googleLoginIn();
break;
case SocialType.Apple:
socialModel = await socialAuthRepository.appleLogin();
break;
}
if (socialModel.ok) {
await iSessionManager.saveToken(accessToken: socialModel.accessToken!);
if (socialModel.user != null) {
await iSessionManager.saveCurrentUser(user: socialModel.user!);
}
yield SocialStateSuccess(socialModel: socialModel);
return;
}
yield SocialStateFailed(
message: socialModel.message ?? 'An unknown error occured.');
}
}