verifyCode method
Implementation
Future<void> verifyCode() async {
try {
state = state.copyWith(isLoading: true, showError: false, errorMessage: null);
if (state.verificationCode.isEmpty) {
String errorMessage = 'Verification code is empty';
if (_context != null) {
errorMessage = VerificationStrings(_context!).enterValidCode;
}
throw Exception(errorMessage);
}
if (state.verificationType == VerificationType.phone) {
final request = PhoneVerificationConfirmRequest(
code: state.verificationCode,
);
await ApiClient.shared.perform(request);
} else {
final request = EmailVerificationConfirmRequest(
code: state.verificationCode,
);
await ApiClient.shared.perform(request);
}
state = state.copyWith(
isLoading: false,
isVerified: true,
);
} catch (e) {
String errorMessage = e.toString();
if (_context != null) {
errorMessage = VerificationStrings(_context!).failedToVerifyCode(e.toString());
}
state = state.copyWith(
isLoading: false,
showError: true,
errorMessage: errorMessage,
);
}
}