signUp method
Implementation
Future<Map?> signUp(String email, String mobile, String password) async {
Map data = {'email': email, 'mobile': mobile, 'password': password};
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/auth/users/"),
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);
await SharedPreferences.getInstance().then((value) {
value.setString('email', jsonData["email"].toString());
value.setString('mobile', jsonData["mobile"].toString());
value.setString('referralCode', jsonData["referralCode"].toString());
value.setString('username', jsonData["username"].toString());
value.setInt('id', jsonData["id"].toInt());
return {
"status": "success",
"email": jsonData["email"],
"mobile": jsonData["mobile"],
"referralCode": jsonData["referralCode"],
"username": jsonData["username"],
"id": jsonData["id"]
};
});
} else if (response.statusCode == 400) {
jsonData = json.decode(response.body);
var error = jsonData["password"]![0] == null
? "Unable to create account. Check if account already exists"
: jsonData["password"]![0];
return {
"status": "error",
"error": error,
};
} else {
if (debug) print("Error Requesting API");
return null;
}
}