executeRawRequest method

Future executeRawRequest({
  1. required HttpMethod method,
  2. required Uri uri,
  3. dynamic body,
})

Executes a raw request with authentication to the specified Uri with specified HttpMethod and with the specified body (if any)

returns a Map of response data if the request is a success.

Implementation

Future<dynamic> executeRawRequest({required HttpMethod method, required Uri uri, dynamic body}) async {
  if (!_isInitialized) {
    callback.invokeErrorCallback('Client is not initialized yet. Try calling init()');
    return null;
  }

  try {
    Response<dynamic> response;

    if (body == null) {
      response = await _client.requestUri(
        uri,
        options: Options(
          contentType: ContentType.json.value,
          responseType: ResponseType.json,
          method: method.humanized.toUpperCase(),
        ),
      );
    } else {
      response = await _client.requestUri(
        uri,
        data: body,
        options: Options(
          contentType: ContentType.json.value,
          responseType: ResponseType.json,
          method: method.humanized.toUpperCase(),
        ),
      );
    }

    if (response.statusCode != 200) {
      return null;
    }

    return response.data is String ? jsonDecode(response.data) : response.data;
  } on DioError catch (e) {
    callback.invokeRequestErrorCallback(e);
    return null;
  }
}