starkdmi / download_manager

Isolated download manager with progress, cancellation, pause and resume
https://pub.dev/packages/isolated_download_manager
BSD 3-Clause "New" or "Revised" License
15 stars 2 forks source link

Is Batch download supported? #6

Closed pslm93 closed 1 year ago

pslm93 commented 1 year ago

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.

starkdmi commented 1 year ago

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
}