finished-flutter-firebase-ddd-course
finished-flutter-firebase-ddd-course copied to clipboard
(flutter_bloc 8.0.1) Emitting streamed event in sign_in_form_bloc
Previously we've used these code blocks for reusing the same functionality to do Login and Registration
Stream<SignInFormState> _performActionAuthFacadeWithEmailAndPassword(
Future<Either<AuthFailure, Unit>> Function({
required EmailAddress emailAddress,
required Password password,
})
forwardedCall,
) async* {
Either<AuthFailure, Unit>? failureOrSucces;
final isEmailValid = state.emailAddress.isValid();
final isPasswordValid = state.password.isValid();
if (isEmailValid && isPasswordValid) {
yield state.copyWith(
isSubmitting: true,
authFailureOrSuccessOption: none(),
);
failureOrSucces = await forwardedCall(
emailAddress: state.emailAddress,
password: state.password,
);
} else {
// failureOrSucces = none();
}
yield state.copyWith(
isSubmitting: false,
showErrorMessages: AutovalidateMode.always,
authFailureOrSuccessOption: optionOf(failureOrSucces), //if null then none
//if some then some (handy use of ternary)
);
}
and we accessed this method as like,
registerWithEmailAndPasswordPressed: (e) async* {
yield* _performActionAuthFacadeWithEmailAndPassword(
_authFacade.registerWithEmailAndPassword);
},
signInWithEmailAndPasswordPressed: (e) async* {
yield* _performActionAuthFacadeWithEmailAndPassword(
_authFacade.signInWithEmailAndPassword);
},
What should we do now??
hey, have you found a way? If so could you please share it?
hey, have you found a way? If so could you please share it?
nope!
hey, have you found a way? If so could you please share it?
nope!
Just return the new state from the function instead of yielding or emitting it directly. Then store this new state in a variable inside the event handler and emit it.
hey, have you found a way? If so could you please share it?
nope!
Just return the new state from the function instead of yielding or emitting it directly. Then store this new state in a variable inside the event handler and emit it.
I hope that's the way!