android - 如何在颤振中设置 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");
}
解决方案
替换onProgress
为onReceiveProgress
。
发生此类问题时,请始终检查功能实现。
推荐阅读
- postgresql - postgres 无法访问 777 文件
- c++ - 如何从 C++ 中的未命名派生类调用非默认父构造函数?
- java - Spring Cloud Kinesis Binder 如何为生产者处理错误 - 根据文档,它不起作用
- android-intent - 如何在没有 intent.addFlags 的情况下将意图从适配器传递给 Activity?
- angular - 如何在计时器中继续 catchError (rxjs)
- python-3.x - VS 代码中的 EOF 错误(也不能在终端中工作)
- python - 尝试在序列化程序“QuestionSerializer”上获取字段“choice_option_set”的值时出现 AttributeError
- javascript - 如何在没有任何提交按钮的情况下提交模板驱动的角度表单?
- r - Rpart vs. caret rpart“错误:重采样的性能度量中存在缺失值”
- python - 在 win10 上安装 Twisted