starkdmi/download_manager

Is Batch download supported?

pslm93 opened this issue · 1 comments

pslm93 commented

Looking at different flutter packages for downloading, I have a question regarding the isolated download manager. Does it support batch downloads? Or is it possible to set it up? I have a requirement where for example I have 10 things to download and the progress and status of all the 10 things being downloaded needs to be reported to the UI as one. For example if one fails then the whole download has failed, if it is paused, then all the download tasks need to be paused.

For a single progress for multiple downloads you can use this code:

var completed = 0, failed = 0;
for (final request in requests) {
   request.events.where((event) => event is DownloadState && event == DownloadState.finished).listen((_) {
      debugPrint("Completed: ${(++completed / requests.length * 100.0).toStringAsFixed(2)}%");
   }, onError: (_) {
      debugPrint("Failed: ${(++failed / requests.length * 100.0).toStringAsFixed(2)}%");

      // TODO: Cancel all requests here if required

   });
}

Batch pause/resume/cancel:

for (final request in requests) {
  request.pause(); // resume, cancel
}