0

I have a _downloadInIsolate(List args) function that works in an isolate. I call it from the VideoDownloadScreen widget. In this widget, after the code responsible for creating and communicating with the isolate, I have the following code:

      _receivePort.close();
      _isolate.kill();
      if (_progress == 100.0) {
        Provider.of<AppStateManager>(context, listen: false)
            .completeDownloadingAssets(true);
      } else {
        Provider.of<AppStateManager>(context, listen: false)
            .completeDownloadingAssets(false);
      }

Works well, but the user can close the widget and then this code will never execute (_downloadInIsolate() still working of course, but the user has no information that the download is finished). I use information about whether assets have been downloaded in several widgets, so I need the Provider.

I only found this link. Is this the only solution? Creating ReceivePort in AppStateManager (in my case) and registering it with IsolateNameServer.registerPortWithName? And then in the isolate find port with IsolateNameServer.lookupPortByName and send a download completion message? Do you have any other suggestions?

What about killing the isolate at the end of the process?

tmp
  • 56
  • 5
  • What about placing this code in the dispose method as well? – Luis Utrera Feb 02 '23 at 17:23
  • @LuisUtrera, thanks for your answer. This code executes only after finishing downloading (or on an error). If I place it in the dispose method, if the user leaves the widget, the download process will stop. OK, maybe I didn't make it very clear, but that's why I used an isolate so that the download process will also continue after the user navigates to other widgets. – tmp Feb 02 '23 at 22:56

0 Answers0