我正在使用 Riverpod 进行状态管理。
class SignInStateNotifier extends StateNotifier<SignInFormStates> {
SignInStateNotifier(this._authFacade) : super(SignInFormStates.initial());
final IAuthFacade _authFacade;
void mapEventToState(SignInFormEvents signInFormEvents) {
state = signInFormEvents.when(
emailChanged: (value) => state.copyWith(
emailAddress: EmailAddress(value),
authFailureOrSuccess: none(),
),
passwordChanged: (value) => state.copyWith(
password: Password(value),
authFailureOrSuccess: none(),
),
signInWithEmailAndPasswordPressed: () async* {
yield* _performActionOnAuthFacade(
_authFacade.signInWithEmailAndPassword);
});
}
我在这里遇到错误
signInWithEmailAndPasswordPressed: () async* {
yield* _performActionOnAuthFacade(
_authFacade.signInWithEmailAndPassword);
});
参数类型“Stream Function()”不能分配给参数类型“SignInFormStates Function()”。
我的__performActionOnAuthFacade
功能
Stream<SignInFormStates> _performActionOnAuthFacade(
Future<Either<AuthFailure, Unit>> Function({
@required EmailAddress emailAddress,
@required Password password,
})
forwardCall,
) async* {
Either<AuthFailure, Unit> failureOrSuccess;
if (state.emailAddress.isValid() && state.password.isValid()) {
yield state.copyWith(
isSubmitting: true,
authFailureOrSuccess: none(),
);
failureOrSuccess = await _authFacade.registerWithEmailAndPassword(
emailAddress: state.emailAddress, password: state.password);
}
yield state.copyWith(
isSubmitting: false,
showErrorMessage: true,
authFailureOrSuccess: optionOf(failureOrSuccess));
}
请给出解决此错误的解决方案。提前致谢。