fix(auth): improve resendCode with status tracking and return value
This commit is contained in:
@@ -152,17 +152,28 @@ class RegisterCubit extends Cubit<RegisterState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> resendCode() async {
|
||||
if (state.pendingEmail == null) return;
|
||||
Future<bool> resendCode() async {
|
||||
if (state.pendingEmail == null) return false;
|
||||
|
||||
emit(state.copyWith(status: FormzSubmissionStatus.inProgress));
|
||||
|
||||
try {
|
||||
await _repository.signupResend(
|
||||
SignupResendRequest(email: state.pendingEmail!),
|
||||
);
|
||||
emit(state.copyWith(codeSent: true));
|
||||
emit(
|
||||
state.copyWith(status: FormzSubmissionStatus.success, codeSent: true),
|
||||
);
|
||||
return true;
|
||||
} catch (e) {
|
||||
final message = e is ApiException ? e.message : e.toString();
|
||||
emit(state.copyWith(errorMessage: message));
|
||||
final message = e is ApiException ? e.message : '验证码发送失败,请重试';
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: FormzSubmissionStatus.failure,
|
||||
errorMessage: message,
|
||||
),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -94,9 +94,9 @@ class _RegisterVerificationViewState extends State<RegisterVerificationView> {
|
||||
|
||||
Future<void> _handleResendCode() async {
|
||||
final cubit = context.read<RegisterCubit>();
|
||||
await cubit.resendCode();
|
||||
final success = await cubit.resendCode();
|
||||
|
||||
if (cubit.state.codeSent && mounted) {
|
||||
if (success && mounted) {
|
||||
_startCountdown();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user