postRequest static method

Future<Response> postRequest({
  1. required String endpoint,
  2. required Map<String, dynamic> body,
  3. String? key,
  4. bool customUrl = false,
})

Implementation

static Future<Response> postRequest(
    {required String endpoint,
    required Map<String, dynamic> body,
    String? key,
    bool customUrl = false}) async {
  late var headerWithToken;
  if (key != null) {
    headerWithToken = {
      "Content-Type": "application/json",
      "x-growlytics-key": "$key",
      "glytics_env": "production",
      "Accept": "application/json"
    };
  }

  Uri uri = (customUrl)
      ? Uri.parse(endpoint)
      : Uri.parse(Endpoints.baseUrl2 + endpoint);

  Response response = await post(uri,
          body: jsonEncode(body),
          headers: (key != null) ? headerWithToken : _header)
      .timeout(
          Duration(
            seconds: 30,
          ), onTimeout: () {
    return Response("Time Out", 408);
  });

  return response;
}