flutter_downloader
flutter_downloader copied to clipboard
Bad state: Stream has already been listened to.
I'm trying to separate the UI and the logic by using providers with ChangeNotifier. First round works perfectly fine but when tried to open the module again getting the error : Bad state: Stream has already been listened to. Any idea how to go about this?
Sounds like you're closing the ReceivePort on dispose(as you should). but you should create a new ReceivePort when reopening the "module" because once you call close on a stream, you can not longer listen to it.
I have some issue .
Resolve by add static before method
static void downloadCallback(String id, DownloadTaskStatus status, int progress)
I have same issue, i'am using bloc to separate ui and logic. i solved it by creating new ReceivePort instance every bloc called, so i make the port variable late.
late ReceivePort _port;
void registerPort() {
_port = ReceivePort();
IsolateNameServer.registerPortWithName(
_port.sendPort,
'downloader_send_port',
);
_port.listen((dynamic data) {
DownloadTaskStatus status = data[1];
int progress = data[2];
emit(state.copyWith(
progress: progress,
downloadTaskStatus: status,
));
});
FlutterDownloader.registerCallback(downloadCallback);
}