downloadUri method

Future<BasicModel> downloadUri(
  1. Uri uri,
  2. String savePath, {
  3. bool? loading,
  4. dynamic tag,
  5. dynamic options,
  6. dynamic onReceiveProgress,
  7. dynamic cancelToken,
  8. Object? data,
  9. bool dataToJson = true,
  10. Map<String, dynamic>? params,
  11. bool deleteOnError = true,
  12. String lengthHeader = Headers.contentLengthHeader,
  13. Duration receiveTimeout = const Duration(seconds: 40),
  14. Duration sendTimeout = const Duration(seconds: 40),
})

文件下载 File download

Implementation

Future<BasicModel> downloadUri(Uri uri, String savePath,
    {bool? loading,
    dynamic tag,
    Options? options,
    ProgressCallback? onReceiveProgress,
    CancelToken? cancelToken,
    Object? data,
    bool dataToJson = true,
    Map<String, dynamic>? params,
    bool deleteOnError = true,
    String lengthHeader = Headers.contentLengthHeader,
    Duration receiveTimeout = const Duration(seconds: 40),
    Duration sendTimeout = const Duration(seconds: 40)}) async {
  assert(_singleton != null, '请先调用 initialize');
  if (hasNetWork) return notNetWorkModel;
  _addLoading(loading);
  data = jsonEncode(basicDioOptions.extraUriData?.call(uri, data) ?? data);
  uri = basicDioOptions.extraUri?.call(uri) ?? uri;
  final res = await dio.downloadUri(uri, savePath,
      onReceiveProgress: onReceiveProgress,
      options: _initBasicOptions(options, uri.path)
          .copyWith(receiveTimeout: receiveTimeout, sendTimeout: sendTimeout),
      data: dataToJson ? jsonEncode(data) : data,
      deleteOnError: deleteOnError,
      lengthHeader: lengthHeader,
      cancelToken: cancelToken);
  return _response(res, tag);
}