download method

Future<BasicModel> download(
  1. String path,
  2. String savePath, {
  3. bool? loading,
  4. dynamic tag,
  5. Options? options,
  6. ProgressCallback? onReceiveProgress,
  7. CancelToken? 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> download(String path, 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 = basicDioOptions.extraData?.call(path, data) ?? data;
  final res = await dio.download(path, savePath,
      onReceiveProgress: onReceiveProgress,
      options: _initBasicOptions(options, path)
          .copyWith(receiveTimeout: receiveTimeout, sendTimeout: sendTimeout),
      data: dataToJson ? jsonEncode(data) : data,
      deleteOnError: deleteOnError,
      lengthHeader: lengthHeader,
      cancelToken: cancelToken);
  return _response(res, tag);
}