flutter_downloader icon indicating copy to clipboard operation
flutter_downloader copied to clipboard

how to check when all the download are finished

Open amedeopro opened this issue 3 years ago • 3 comments

Hello, how can i check when all the download are finished with flutter_downloader package? I have many downloads and i would like check when all the download are finished and not one by one.

Thank you

amedeopro avatar Apr 28 '22 19:04 amedeopro

You can achieve what you want like this (sample taken from README and modified):

ReceivePort _port = ReceivePort();

@override
void initState() {
  super.initState();

  IsolateNameServer.registerPortWithName(_port.sendPort, 'downloader_send_port');
  _port.listen((dynamic data) {
    _getAllDownloadTasks();
    setState((){ });
  });

  FlutterDownloader.registerCallback(downloadCallback); // see README for this
}

Future<void> _getAllDownloadTasks() async {
  final allDownloadTasks = await FlutterDownloader.loadTasks();

  var allCompleted = true;
  for (final downloadTask in allDownloadTasks) {
    if (downloadTask.status == DownloadTaskStatus.complete) {
      print('this task is finished');
    } else {
      allCompleted = false;
    }

  if (allCompleted) {
    print('all downloads are complete');
  }
}

Does it solve your problem @amedeopro? If yes, feel free to close the issue :)

bartekpacia avatar May 24 '22 09:05 bartekpacia

Thank you very much, I'll try and let you know, do you know if anyone is updating the package for windows compatibility? @bartekpacia

amedeopro avatar May 25 '22 13:05 amedeopro

@amedeopro I'm pretty sure nobody is working on this, unfortunately.

You can subscribe to issue #617 to be up to date. Maybe someone will start working on it in the future.

bartekpacia avatar May 25 '22 14:05 bartekpacia