postRequest static method

Future postRequest(
  1. Map map,
  2. String api, {
  3. Map<String, String>? header,
})

Implementation

static Future<dynamic> postRequest(Map map, String api,
    {Map<String, String>? header}) async {
  var url = Uri.parse('$apiEndpoint/$api');

  try {
    http.Response response = await http.post(url, body: map, headers: header);
    if (response.statusCode == 200) {
      String data = response.body;
      var decodedData = jsonDecode(data);
      return decodedData;
    } else {
      return 'failed';
    }
  } catch (e) {
    throw Exception('No internet connectivity');
  }
}