gpt4 book ai didi

flutter - 文本验证器无法使用bloc和卡住

转载 作者:行者123 更新时间:2023-12-03 17:22:18 25 4
gpt4 key购买 nike

电子邮件地址的验证无法使用DDD模式进行操作,我使用的是dartz,bloc和frozen这样做。
我试图发现错误,但我不能。
电子邮件地址是:

class _EmailAdressInput extends _ListOfInputs {
const _EmailAdressInput();
@override
Widget build(BuildContext context) {
return BlocBuilder<AuthBloc, AuthBlocState>(builder: (context, state) {
return TextFormField(
focusNode: emailAddressNode,
autocorrect: false,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Email Address',
),
validator: (value) {
return context.read<AuthBloc>().state.email.value!.fold(
(l) => l.maybeMap(
orElse: () {}, invalidEmail: (_) => "Invalid Email"),
(r) => null);
},
onChanged: (value) {
return context.read<AuthBloc>().add(
AuthBlocEvent.emailAddressEvent(emailAdressEventValue: value));
},
onFieldSubmitted: (value) {
emailAddressNode!.unfocus();
FocusScope.of(context).requestFocus(passwordNode);
},
);
});
}
}
使用卡住的事件:
@freezed
abstract class AuthBlocEvent with _$AuthBlocEvent {
const factory AuthBlocEvent.emailAddressEvent(
{required String emailAdressEventValue}) = _EmailAddressEvent;
}
使用卡住库的状态是:
@freezed
abstract class AuthBlocState with _$AuthBlocState {
const factory AuthBlocState({
required Password password,
required bool isSubmitted,
required bool showErrorMessages,

required Option<Either<AuthFailures, Unit>> authFailureOrSuccessOption,
}) = _AuthBlocState;

factory AuthBlocState.initial() => AuthBlocState(
email: EmailAddress(''),
isSubmitted: false,
showErrorMessages: false,
authFailureOrSuccessOption: none(),
);
}
集团是:
  @override
Stream<AuthBlocState> mapEventToState(
AuthBlocEvent event,
) async* {
yield* event.map(
emailAddressEvent: (e) async* {
yield state.copyWith(
email: EmailAddress(e.emailAdressEventValue),
showErrorMessages: true,
authFailureOrSuccessOption: none(),
);
},
okPressedEvent: (e) async* {
// to get the value of
// either we should use option of
// to check either values
// we have to knew that
// both are right
if (state.email.isValueValid()
) {
yield state.copyWith(
isSubmitted: true,
authFailureOrSuccessOption: none(),
);
}
},
);}
验证者为:
Either<ValueFailures, String> emailAddressValidator(String input) {
if (RegExp(r"""^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+""")
.hasMatch(input)) return right(input);
return left(const ValueFailures.invalidEmail(
msg: "Invalid Email"));
}
相等的is值(value)对象是:
abstract class ValueObject {
const ValueObject();
Either<ValueFailures, String>? get value;
Either<ValueFailures, String>? get extraValue;

bool isValueValid() => value!.isRight();
bool isExtraValueValid() => extraValue!.isRight();

@override
String toString() => 'ValueObject(value: $value, extraValue: $extraValue)';

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;

return other is ValueObject &&
other.value == value &&
other.extraValue == extraValue;
}

@override
int get hashCode => value.hashCode ^ extraValue.hashCode;

}

最佳答案

您没有在您的集团中映射emailAdressEvent。同样,当您处于context.read<AuthBloc>().state时,您不需要使用blocBuilder,您可以只使用state。

关于flutter - 文本验证器无法使用bloc和卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66956994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com