0

In my HookWidget, I call:

final myData = useStream<MyData>(service.getDataStream(), initialData: {});

Unfortunately, when going back to the same screen/ navigating, I get Bad state: Stream has already been listened to.. This is probably because the previous stream does not get closed, and can't be listened to again.

Why doesn't useStream close the stream, or do I have to do it (how?, its created in the build method so it can be closed in dispose)? The service contains a StreamController:

class Service {
    final _dataController = StreamController<MyData>();
    
    Stream<Data> getDataStream() {
    return _dataController.stream;
  }
}
Ben Butterworth
  • 22,056
  • 10
  • 114
  • 167

0 Answers0