post function

Future<Response?> post(
  1. String baseAddress,
  2. String endpoint, {
  3. Map<String, dynamic>? body,
})

Implementation

Future<http.Response?> post(String baseAddress, String endpoint,
    {Map<String, dynamic>? body}) async {
  var response;
  try {
    var uri;
    baseAddress = baseAddress.replaceFirst("https://", "");
    uri = Uri.https(baseAddress, '$API_VERSION$endpoint');
    response = await http.post(
      uri,
      body: json.encode(body),
      headers: {
        HttpHeaders.acceptHeader: '*/*',
        HttpHeaders.contentTypeHeader: 'application/json',
      },
    );

    return returnResponseOrThrowException(response);
  } on IOException {
    throw NetworkException();
  } catch (e) {
    print(e);
    return response;
  }
}