resendOtp method

Future<void> resendOtp()
inherited

Implementation

Future<void> resendOtp() async {
  final verificationId = _verificationId;
  if (verificationId == null) {
    setLoading(isLoading: false, error: 'Verification ID is required');
    goToPage(VoAuthPageKeys.phoneSignIn);
    return;
  }

  setLoading(isLoading: true, error: null);

  final result = await otpService.resendOtp(
    RefreshOtpPayload(verificationId: verificationId),
  );

  await result.when(
    success: (response) {
      if (!ref.mounted) return;
      state = state.copyWith(
        sendOtpResponse: response,
        isLoading: false,
        error: null,
      );
    },
    failure: (error) {
      if (!ref.mounted) return;
      setLoading(isLoading: false, error: error.message);
    },
  );
}