[英]how to set dio package in flutter?
I want to create flutter apps for downloading files from inte.net but when i use the dio package , I get the error;我想创建 flutter 应用程序以从 inte.net 下载文件,但是当我使用dio package时,出现错误; The named parameter 'onProgress' isn't defined, what should I do?
未定义命名参数“onProgress”,我该怎么办?
my function我的 function
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");
}
Replace onProgress
with onReceiveProgress
.将
onProgress
替换为onReceiveProgress
。
Always check the function implementation when issues like this occurred.发生此类问题时,请务必检查 function 实施。
The method signature for the download
method in Dio 4.0.0 is the following: Dio 4.0.0 中
download
方法的方法签名如下:
Future<Response> download(
String urlPath,
savePath, {
ProgressCallback? onReceiveProgress,
Map<String, dynamic>? queryParameters,
CancelToken? cancelToken,
bool deleteOnError = true,
String lengthHeader = Headers.contentLengthHeader,
data,
Options? options,
});
So you should use onReceiveProgress
instead of onProgress
.所以你应该使用
onReceiveProgress
而不是onProgress
。
onProgress
was the initial parameter that was used when the Dio package was created. onProgress
是创建 Dio package 时使用的初始参数。 This has been changed in the v2.0.14 release .这在 v2.0.14 版本中已更改。 It seems like a small part of the initial code docs remained intact since that release.
自该版本发布以来,似乎有一小部分初始代码文档保持完好无损。
If that is what confused you, it might be a good thing to open an issue on the Dio GitHub project.如果这让您感到困惑,那么在 Dio GitHub 项目上提出问题可能是一件好事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.