首页 > 解决方案 > 如何在颤振中设置 dio 包?

问题描述

我想创建用于从互联网下载文件的颤振应用程序,但是当我使用dio 包 时,我得到了错误;未定义命名参数“onProgress”,我该怎么办?

我的功能

 Future<void> downloadFile() async {
    Dio dio = Dio();

    try {
      var dir = await getApplicationDocumentsDirectory();

      await dio.download(imgUrl, "${dir.path}/myimage.jpg",
          onProgress: (rec, total) {
            print("Rec: $rec , Total: $total");

            setState(() {
              downloading = true;
              progressString = ((rec / total) * 100).toStringAsFixed(0) + "%";
            });
          });
    } catch (e) {
      print(e);
    }

    setState(() {
      downloading = false;
      progressString = "Completed";
    });
    print("Download completed");
  }

标签: androidflutterdart

解决方案


替换onProgressonReceiveProgress

发生此类问题时,请始终检查功能实现。


推荐阅读