postRequest method
Sends an HTTP POST request with the UrlRequest object waiting for a 200, 202 or 204 status code.
Implementation
Future<dynamic> postRequest(UrlRequest request) async {
final response = await http.post(request.url,
headers: request.headers,
body: request.body,
encoding: request.encoding);
if (response.statusCode == 200) {
try {
return jsonDecode(response.body);
} catch (error) {
return Future.error(error);
}
} else {
return Future.error("The server did not return a 200 code");
}
}