The state management is not working for me.
class SignInStateNotifier extends StateNotifier<SignInFormStates> {
SignInStateNotifier(this._authFacade) : super(SignInFormStates.initial());
final IAuthFacade _authFacade;
Stream<SignInFormStates> mapEventToState(SignInFormEvents events) async* {
yield* events.map(emailChanged: (value) async* {
yield state.copyWith(
emailAddress: EmailAddress(value.email),
authFailureOrSuccess: none(),
);
}, passwordChanged: (value) async* {
state.copyWith(
password: Password(value.password),
authFailureOrSuccess: none(),
);
}, signInWithEmailAndPasswordPressed: (value) async* {
Either<AuthFailure, Unit> failureOrSuccess;
if (state.emailAddress.isValid() && state.password.isValid()) {
yield state.copyWith(
isSubmitting: true,
authFailureOrSuccess: none(),
);
failureOrSuccess = await _authFacade.signInWithEmailAndPassword(
emailAddress: state.emailAddress,
password: state.password,
);
}
yield state.copyWith(
isSubmitting: false,
showErrorMessage: true,
authFailureOrSuccess: optionOf(failureOrSuccess),
);
});
}
}
Form(
child: Column(
children: [
TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
onChanged: (value) => state
.mapEventToState(SignInFormEvents.emailChanged(value)),
validator: (_) => state2.emailAddress.validatedObject.fold(
(l) => l.maybeMap(
orElse: () => null,
invalidEmail: (_) => "Invalid Email"),
(_) => null),
),
FlatButton(
onPressed: () {
state.mapEventToState(SignInFormEvents
.signInWithEmailAndPasswordPressed());
},
child: Text("Hello World"))
],
)
);
What mistake have I made? Please give me a solution.
Thanks in advance.