ResoCoder / finished-flutter-firebase-ddd-course

https://resocoder.com/flutter-firebase-ddd-course
GNU General Public License v3.0
396 stars 114 forks source link

(flutter_bloc 8.0.1) Emitting streamed event in sign_in_form_bloc #21

Closed Meshkat-Shadik closed 2 years ago

Meshkat-Shadik commented 2 years ago

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

bilalep commented 2 years ago

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

Meshkat-Shadik commented 2 years ago

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

nope!

bilalep commented 2 years ago

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.

Meshkat-Shadik commented 2 years ago

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!