我正在尝试下载多个文件使用dio软件包。从这个git发行中,我发现可以使用future.wait来完成这个任务,尽管我能够同时更新多个文件,但不能更新数据库。下面是下载代码片段
download(Attachment attachment) => work(context, () async {
final dio = Dio();
final path = await getLocalFilePath(attachment);
var downloadRequest = dio.download(
attachment.url,
path,
deleteOnError: true,
onReceiveProgress: (count, total) {
setState(
() {
_downloadProgress[attachment.url] = count / total;
print(_downloadProgress[attachment.url]);
},
);
},
).then(
(value) async {
await ReviewDownloadsDB().add({
'id': attachment.id,
'name': attachment.name,
'url': attachment.url,
'path': path
});
},
);
Future.wait([downloadRequest]);
});有人能告诉我哪里出错了吗?下载后如何将下载的项目添加到我的ObjectDB数据库中。屏幕的完整代码是这里。
发布于 2022-09-01 00:53:21
如果您不介意使用不同的包,则可以使用下装载机包同时下载多个文件。默认的最大并发下载任务集为3(3),您可以按照此指南更改此配置。
然后可以使用FlutterDownloader.enqueue()创建下载任务。
final taskId = await FlutterDownloader.enqueue(
url: 'your download link',
headers: {}, // optional: header send with url (auth token etc)
savedDir: 'the path of directory where you want to save downloaded files',
showNotification: true, // show download progress in status bar (for Android)
openFileFromNotification: true, // click on notification to open downloaded file (for Android)
);https://stackoverflow.com/questions/63897850
复制相似问题