downloadFile method

Future<Map> downloadFile(
  1. String urlPath,
  2. String savePath, {
  3. int localId = 0,
  4. dynamic cDio,
  5. 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;
  }
}