put method
Implementation
Future<dynamic> put(String endpoint, Object data) async {
String url = '$baseurl$endpoint';
print(url);
var header = {
'Content-Type': Headers.jsonContentType,
'Authorization': controller.publicKey,
"signature": generateHmacSha512(data.toString()),
};
debugPrint(url);
debugPrint("headers: \n $header");
debugPrint("unencrypted payload \n ${data.toString()}");
// final decrypted = encrypter.decrypt(encrypted, iv: iv);
// debugPrint('Decrypted: $decrypted');
try {
Response response;
final options = Options(headers: header);
response = await dio.put(url, options: options, data: data);
if (response.statusCode == 200) {
debugPrint(jsonEncode(response.data));
return response.data;
} else if (response.statusCode == 401) {
return {
"success": false,
"message": "Try and login again",
"status": "false",
};
}
} on DioException catch (e) {
if (e.response?.statusCode == 401) {
return {
"success": false,
"message": "Session expired. Please log in again.",
"status": "false",
};
}
debugPrint("error");
debugPrint(e.message);
return {
"success": false,
"message": "Connection error try again later",
"status": "false",
};
// return {"success": false,"message":e.message.toString(),"status":"false"};
}
}