verifyEmailMobile method

Future<bool> verifyEmailMobile(
  1. String type
)

Implementation

Future<bool> verifyEmailMobile(String type) async {
  String input;
  if (type == 'email') {
    if (emailController.text.isEmpty) {
      throw Exception("Email is required");
    }
    input = emailController.text;
  } else if (type == 'mobile') {
    if (mobilenoController.text.isEmpty) {
      throw Exception("Mobile number is required");
    }
    input = mobilenoController.text;
  } else {
    throw Exception("Invalid type: $type");
  }

  if (otpController.text.isEmpty) {
    throw Exception("OTP is required");
  }

  try {
    dynamic response;
    if (type == 'email') {
      response = await NetworkHandler.confirmEmailOrMobile(
          email: input, otp: otpController.text);
    } else {
      response = await NetworkHandler.confirmEmailOrMobile(
          mobileno: input, otp: otpController.text);
    }

    var data = response.data;
    if (response.statusCode == 200) {
      return true;
    } else {
      throw Exception(data['reason']);
    }
  } catch (error) {
    throw Exception(error.toString());
  }
}