postAPICall static method

Future<Map<String, dynamic>> postAPICall({
  1. required String api,
  2. Map<String, dynamic>? body,
  3. Map<String, String>? headersList,
})

Implementation

static Future<Map<String, dynamic>> postAPICall(
    {required String api,
    Map<String, dynamic>? body,
    Map<String, String>? headersList}) async {
  var url = Uri.parse(api);
  var req = Request('POST', url);
  req.headers.addAll(headersList ?? {'Accept': '*/*'});
  req.body = jsonEncode(body ?? {});
  var res = await req.send();
  final resBody = await res.stream.bytesToString();
  var json = jsonDecode(resBody);
  if (res.statusCode >= 200 && res.statusCode < 300) {
    return json;
  } else {
    return json;
  }
}