download method
下载文件
Implementation
Future download(
String url,
String savePath, {
void Function(double)? onReceiveProgress,
Map<String, dynamic>? queryParameters,
CancelToken? cancelToken,
bool deleteOnError = true,
String lengthHeader = Headers.contentLengthHeader,
Object? data,
Options? options,
}) async {
try {
isDownloading = true;
return await _dio.download(
url,
savePath,
cancelToken: cancelToken ?? _cancelToken,
queryParameters: queryParameters,
deleteOnError: deleteOnError,
lengthHeader: lengthHeader,
data: data,
options: options,
onReceiveProgress: (received, total) {
if (total != -1) {
double process = received / total;
if (onReceiveProgress != null) {
onReceiveProgress(process);
}
}
},
);
} catch (e) {
rethrow;
} finally {
isDownloading = false;
}
}