I am trying to download multiple files using dio package. From this git issue I found out that future.wait can be used to achieve this task, though I am able to update multiple files concurrently but cannot update the database. Here's the downloading code snippet
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]);
});
Can someone tell me where I'm going wrong and how can I add the downloaded item to my ObjectDB database after it's downloaded. The complete Code for the screen is present here.