download<T> method

  1. @override
Future<Result<T>> download<T>(
  1. String urlPath,
  2. dynamic savePath, {
  3. dynamic data,
  4. Map<String, dynamic>? queryParameters,
  5. RestApiClientRequestOptions? options,
  6. ProgressCallback? onReceiveProgress,
  7. CancelToken? cancelToken,
  8. bool deleteOnError = true,
  9. String lengthHeader = Headers.contentLengthHeader,
  10. FutureOr<T> onSuccess(
    1. dynamic data
    )?,
  11. FutureOr<T> onError(
    1. dynamic data
    )?,
})
override

Implementation

@override
Future<Result<T>> download<T>(
  String urlPath,
  savePath, {
  data,
  Map<String, dynamic>? queryParameters,
  RestApiClientRequestOptions? options,
  ProgressCallback? onReceiveProgress,
  CancelToken? cancelToken,
  bool deleteOnError = true,
  String lengthHeader = Headers.contentLengthHeader,
  FutureOr<T> Function(dynamic data)? onSuccess,
  FutureOr<T> Function(dynamic data)? onError,
}) async {
  try {
    final response = await _dio.download(
      urlPath,
      savePath,
      queryParameters: queryParameters,
      options: options?.toOptions(),
      data: data,
      onReceiveProgress: onReceiveProgress,
      cancelToken: cancelToken,
      deleteOnError: deleteOnError,
      lengthHeader: lengthHeader,
    );

    return NetworkResult(
      response: response,
      data: await _resolveResult(response.data, onSuccess),
    );
  } on DioException catch (e) {
    await exceptionHandler.handle(e, silent: options?.silentException);

    return NetworkResult(
      response: e.response,
      exception: e,
      statusCode: e.response?.statusCode,
      statusMessage: e.response?.statusMessage,
    );
  }
}