post method

Future post(
  1. String endpoint,
  2. Object data,
  3. String publicKey,
  4. String secretKey,
)

Implementation

Future<dynamic> post(String endpoint, Object data,String publicKey,String secretKey) async {
  String url = '$baseurl$endpoint';
  // dev.log(url);
  var header = {
    'Content-Type': Headers.jsonContentType,
    'Authorization': publicKey,
    "signature": generateHmacSha512(jsonEncode(data),secretKey),
  };

  // debugPrint(url);
  // debugPrint(jsonEncode(data));
  // debugPrint(generateHmacSha512(jsonEncode(data),secretKey));
  // 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.post(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"};
  }
}