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 JSON Object

Implementation

@override
Future<Map<dynamic, dynamic>> httpRequest(
    Uri? uri, Map<String, dynamic> request) {
  final completer = Completer<Map<String, dynamic>>();
  final reqText = json.encode(request);
  final headers = <String, String>{contentType: jsonMimeType};
  HttpRequest.request(uri.toString(),
          method: 'POST',
          withCredentials: false,
          requestHeaders: headers,
          sendData: reqText)
      .then((HttpRequest req) {
    if (req.responseText != null) {
      final Map<String, dynamic> resp = json.decode(req.responseText!);
      completer.complete(resp);
      return completer.future;
    } else {
      completer.complete(<String, dynamic>{});
      return completer.future;
    }
  }, onError: (final error) {
    completer.complete(<String, dynamic>{});
    return completer.future;
  });
  return completer.future;
}