httpRequest method

  1. @override
Future<Map> httpRequest(
  1. Uri? uri,
  2. Map<String, dynamic> request
)
override

Processes the HTTP request returning the HTTP response as a map

Implementation

@override
Future<Map<dynamic, dynamic>> httpRequest(
    Uri? uri, Map<String, dynamic> request) {
  final client = HttpClient();
  final completer = Completer<Map<dynamic, dynamic>>();
  client.postUrl(uri!).then((HttpClientRequest req) {
    final dynamic payload = json.encode(request);
    req.headers.add(HttpHeaders.contentTypeHeader, jsonMimeType);
    req.contentLength = payload.length;
    req.write(payload);
    req.close().then((HttpClientResponse resp) {
      resp.listen(
        (dynamic data) {
          final Map<dynamic, dynamic>? payload =
              json.decode(String.fromCharCodes(data));
          completer.complete(payload);
        },
        onError: print,
      );
    });
  }, onError: print);
  return completer.future;
}