I have StreamBuilder
Widget build(BuildContext context) {
return StreamBuilder(
initialData: false,
stream: widget.stream, ...
For initializing widget I call:
_EventSpeakerPager(..., streamController.stream.distinct());
And this produce error "Bad state: Stream has already been listened to."
Without distinct()
it works, but it's not suitable for me.
I've tried asBroadcastStream()
and got the same error
Does anybody know, how can I handle this
P.S. I've already looked into these:
topic1, topic2, topic3 - nothing helps
P.P.S.
When I use stream without StreamBuilder
- all works fine
void initState() {
super.initState();
widget.stream.listen((bool data) {
setState(() {
...
});
});
}
A stream builder is a widget that can convert user-defined objects into a stream.
A controller with the stream it controls. This controller allows sending data, error and done events on its stream. This class can be used to create a simple stream that others can listen on, and to push events to that stream.
To use StreamBuilder , you need to call the constructor below. Basically, you need to create a Stream and pass it as the stream argument. Then, you have to pass an AsyncWidgetBuilder which can be used to build the widget based on the snapshots of the Stream .
So, all I've needed to do is replace
final StreamController<bool> streamController = StreamController<bool>();
with final StreamController<bool> streamController = StreamController<bool>.broadcast();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With