callApi method

  1. @override
dynamic callApi(
  1. String url,
  2. Map<String, dynamic>? body, {
  3. Map<String, String>? headers,
  4. Map<String, dynamic>? queryParameters,
  5. dynamic loading(
    1. bool loading
    )?,
})
override

Implementation

@override
callApi(String url, Map<String, dynamic>? body,
    {Map<String, String>? headers,
    Map<String, dynamic>? queryParameters,
    Function(bool loading)? loading}) async {
  dynamic apiResponse;
  DebugUtils.showLog('put -$url');
  loading?.call(true);
  try {
    final http.Response response = await http.delete(
      SimplifiedUri.uri(url, queryParameters),
      headers: {
        'Content-Type': 'application/json',
        'authorizationToken': /*xAuthToken ?? */ '',
        if (headers != null) ...headers
      },
      body: body != null ? jsonEncode(body) : null,
    );

    try {
      DebugUtils.showLog('Query parameters//////////////: $queryParameters ');

      DebugUtils.showLog('Api Request//////////////: ${jsonEncode(body)} ');

      apiResponse = returnResponse(response: response);
      DebugUtils.showLog('Api response:  ${response.body}');
      loading?.call(false);
      return apiResponse;
    } catch (e) {
      loading?.call(false);
      DebugUtils.showLog('Post api exception: $e');
      apiResponse = json.decode(response.body.toString());
      return apiResponse;
    } finally {
      loading?.call(false);
    }
  } on SocketException {
    DebugUtils.showLog('Post api socket  exception: ');
    rethrow;
  }
}