download method

Future<T> download([
  1. RequestParams options = const RequestParams()
])

下载文件

Implementation

Future<T> download([RequestParams options = const RequestParams()]) async {
  final baseOptions = await getOptions(options);
  final d = await getDio(baseOptions);
  assert(options.downloadUrl != null, "请传入下载链接");
  assert(options.savePath != null, "请传入保存路径");
  try {
    final response = await d.download(
        options.downloadUrl!, options.savePath!.path,
        onReceiveProgress: options.onReceiveProgress,
        data: options.data,
        cancelToken: options.cancelToken);
    options.responseResultCallback?.call(response);
    var model = DartTypeModel.createFrom(response.data);
    beforeHandleDartTypeModel(model, options, response);
    return covertToModel(model, options);
  } on dio.DioException catch (e) {
    throw BaseApiException.createFromDioException(e);
  }
}