request<T> method

Future<T> request<T>(
  1. String url, {
  2. String? baseUrl,
  3. String? method,
  4. Options? options,
  5. dynamic data,
  6. bool showLoading = false,
  7. CancelToken? cancelToken,
  8. void onSendProgress(
    1. int,
    2. int
    )?,
  9. void onReceiveProgress(
    1. int,
    2. int
    )?,
})

Implementation

Future<T> request<T>(
  String url, {
  String? baseUrl,
  String? method,
  Options? options,
  data,
  bool showLoading = false,
  CancelToken? cancelToken,
  void Function(int, int)? onSendProgress,
  void Function(int, int)? onReceiveProgress,
}) async {
  try {
    options ??= Options();
    options.method =
        method?.toUpperCase() ?? HttpMethod.get.name.toUpperCase();

    if (showLoading) {
      CommonHelper.showLoading();
    }
    Response response = await _dio.request(
      baseUrl != null ? baseUrl + url : this.baseUrl + url,
      data: data,
      queryParameters:
          options.method == HttpMethod.get.name.toUpperCase() ? data : null,
      options: options,
      cancelToken: cancelToken,
      onSendProgress: onSendProgress,
      onReceiveProgress: onReceiveProgress,
    );
    if (showLoading) {
      CommonHelper.hideLoading();
    }
    return response.data;
  } catch (e) {
    if (showLoading) {
      CommonHelper.hideLoading();
    }
    throw e.toString();
  }
}