1

I'm using the flutter_downloader package to download files with my app. The progress notification is working nicely. but my ReceivePort is not listening to the progress.

  final ReceivePort port = ReceivePort();

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

     IsolateNameServer.registerPortWithName(
        port.sendPort, 'downloader_sendport');

     port.listen((dynamic data) async {
       log('data: $data');  // don't work

     });
     FlutterDownloader.registerCallback(downloadCallback);
   }


@pragma('vm:entry-point')
  static void downloadCallback(
      String id, DownloadTaskStatus status, int progress) {
    log("downloadCallback => $id, $status, $progress"); // works

    final SendPort? send =
        IsolateNameServer.lookupPortByName('downloader_sendport');

   

    send?.send([id, status, progress]);
  }
MedCh
  • 355
  • 4
  • 9

2 Answers2

5

The SendPort needs to receive a primitive object (int), not a DownloadTaskStatus object:

Solution: Change status to primitive status.value when calling send(...):

send?.send([id, status.value, progress]);
BananaNeil
  • 10,322
  • 7
  • 46
  • 66
MedCh
  • 355
  • 4
  • 9
1

Change status to primitive status.value in send method.

BananaNeil
  • 10,322
  • 7
  • 46
  • 66
FaKenKoala
  • 11
  • 3