flutter_downloader icon indicating copy to clipboard operation
flutter_downloader copied to clipboard

Bad state: Stream has already been listened to.

Open Shruti2208 opened this issue 4 years ago • 3 comments

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?

Shruti2208 avatar Dec 12 '20 07:12 Shruti2208

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.

jinyus avatar Dec 17 '20 11:12 jinyus

I have some issue .

Resolve by add static before method


static void downloadCallback(String id, DownloadTaskStatus status, int progress) 

phuongphally avatar Apr 29 '21 13:04 phuongphally

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);
  }

febryardiansyah avatar Jul 22 '22 03:07 febryardiansyah