finished-flutter-firebase-ddd-course icon indicating copy to clipboard operation
finished-flutter-firebase-ddd-course copied to clipboard

(flutter_bloc 8.0.1) Emitting streamed event in sign_in_form_bloc

Open Meshkat-Shadik opened this issue 3 years ago • 1 comments

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??

Meshkat-Shadik avatar Jan 26 '22 20:01 Meshkat-Shadik

hey, have you found a way? If so could you please share it?

bilalep avatar Jul 25 '22 20:07 bilalep

hey, have you found a way? If so could you please share it?

nope!

Meshkat-Shadik avatar Nov 29 '22 11:11 Meshkat-Shadik

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.

bilalep avatar Nov 29 '22 13:11 bilalep

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!

Meshkat-Shadik avatar Nov 29 '22 13:11 Meshkat-Shadik