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?