verifyPhone method

Future<bool> verifyPhone()

Implementation

Future<bool> verifyPhone()async{
  int numberOfTries = 0;
  const int MAX_NUMBER_OF_TRIED = 3;
  bool didUserCancelDialog = false;

  resultPin.value = "";
  bool sendResult = await sendOtp();
  if(sendResult)
  {
  bool confirmOtpResult = false;
  while(confirmOtpResult == false && numberOfTries < MAX_NUMBER_OF_TRIED)
  {
    numberOfTries++;
    cancelTimer();
    startTimer();
    await OtpVerificationView.show(
      barrierDismissible: false,
      onConfirm: () {
        closeDialog();
      },
      onClickClose:(){
        didUserCancelDialog = true;
        closeDialog();
      },
      onResend: () async {
        try {
          resultPin.value = '';
          await sendOtp();
          CustomFlashWidget.showFlashMessage(
            type: FlashType.success,
            title: "Success",
            message: "Otp code resent successfully!",
          );
          cancelTimer();
          startTimer();
        } catch (e) {
          CustomFlashWidget.showFlashMessage(
            type: FlashType.success,
            title: "Error",
            message: e.toString(),
          );
        }
      },
    );
    if(didUserCancelDialog){
      return false;
    }else {
      if(resultPin.value.length<5){
        CustomFlashWidget.showFlashMessage(title: "Error",
            message:"You have entered an incorrect OTP" );
      }else {
        bool confirmResult = await confirmOtp();
        if (confirmResult == false) {
          CustomFlashWidget.showFlashMessage(title: "Error",
              message: "You have entered an incorrect OTP");
        }else{
          return true;
        }
      }
    }
  }
}

    return false;

}