sendOtp method
Implementation
Future<Map?> sendOtp(String email, String phone) async {
Map data = {'email': email, 'mobile': phone};
String? client_id = iAmA == "consultant"
? Params.consultant_client_id
: Params.patient_client_id;
/*Calling the API url */
var jsonData;
final response = await http.post(
Uri.parse(Params.base_url + "/accounts/otp/send"),
body: data,
headers: {"Client-ID": "$client_id"});
if (debug) {
print('Status Code = ' +
response.statusCode.toString() +
". Response: " +
response.body);
}
/*If the response is 200 or 201 (success) then the response will be decoded */
if (response.statusCode == 200 || response.statusCode == 201) {
jsonData = json.decode(response.body);
return {
"status": jsonData["status"],
"reference": jsonData["reference"],
"hasExpired": jsonData["hasExpired"],
"expires": tools.dateUtil(jsonData["expires"].toString()),
"message": jsonData["message"]
};
} else if (response.statusCode >= 400 && response.statusCode >= 499) {
return {"status": jsonData["status"], "message": jsonData["message"]};
} else {
if (debug) print("Error Requesting API");
return null;
}
}