downloadFile method
Future<Map>
downloadFile(
- String urlPath,
- String savePath, {
- int localId = 0,
- dynamic cDio,
- ProgressCallback? onReceiveProgress,
})
Implementation
Future<Map> downloadFile(String urlPath, String savePath,
{int localId = 0, cDio, ProgressCallback? onReceiveProgress}) async {
int _total = 0;
adio.CancelToken cancelToken = adio.CancelToken();
try {
adio.Dio dio = cDio ?? adio.Dio();
await dio.download(urlPath, savePath, cancelToken: cancelToken,
onReceiveProgress: (int count, int total) {
if (onReceiveProgress != null) {
onReceiveProgress(count, total);
}
//进度
_total = total;
FastCache('$localId').value = {
'count': count,
'total': total,
'dio': dio,
'cancelToken': cancelToken
};
}).catchError((e) {
throw e;
});
return {'savePath': savePath, 'total': _total};
} on adio.DioError catch (e) {
print('downloadFile error---------$e');
throw e;
}
}