postRequest static method

Future<Response> postRequest(
  1. String url,
  2. Map<String, dynamic> body, {
  3. Map<String, String>? headers,
  4. int timeout = 30,
})

Implementation

static Future<http.Response> postRequest(
    String url, Map<String, dynamic> body,
    {Map<String, String>? headers, int timeout = 30}) async {
  var initalHeaders = {'Content-Type': 'application/json'};

  if (headers != null) {
    initalHeaders = {...initalHeaders, ...headers};
  }

  final response = await http
      .post(
        Uri.parse(url),
        headers: initalHeaders,
        body: jsonEncode(body),
      )
      .timeout(Duration(seconds: timeout));

  return response;
}