如何在Flutter中使用Dio获取“下载完成文件”的回调?

时间:2019-12-05 07:54:37

标签: flutter flutter-dependencies

我有这个代码

 await dio.download(fileUrl, "${fileDir.path}/$fileName",
          onReceiveProgress: (received, total) {
        if (total != -1) {
          print("Rec: $received , Total: $total");
          debugPrint("Directory path : " + filePath + "/" + fileName);
          setState(() {
            downloadProgressString =
                ((received / total) * 100).toStringAsFixed(0) + "%";
          });
        }
      });

onReceiveProgress 一样,我们是否还有其他用于“ 下载完成”的回调?

1 个答案:

答案 0 :(得分:1)

将来返回回调。

  await dio.download(fileUrl, "${fileDir.path}/$fileName",
      onReceiveProgress: (received, total) {
    if (total != -1) {
      print("Rec: $received , Total: $total");
      debugPrint("Directory path : " + filePath + "/" + fileName);
      setState(() {
        downloadProgressString =
            ((received / total) * 100).toStringAsFixed(0) + "%";
      });
    }
  });
  // HERE
  print("download complete!");