sendOTP method
Implementation
Future sendOTP(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");
}
try {
dynamic response;
if (type == 'email') {
response = await NetworkHandler.sendOtpToEmail(input);
} else {
response = await NetworkHandler.sendOtpToMobile(input);
}
// {"errorcode":6220,"reason":"Otp has been sent to the new email"}
var data = response.data;
if (response.statusCode == 200) {
return true;
} else {
throw Exception(data['reason']);
}
} catch (error) {
throw Exception(error.toString());
}
}