StreamBuilder. Bad state: Stream has already been listened to
Use the rx_dart
library from pubspec: https://pub.dartlang.org/packages/rxdart
Now change your Stream<Something>
declaration to be a BehaviorSubject<Something>
.
(The BehaviorSubject is a kind of stream that has memory of the last value transmited. There is other subjects available on the library like the PublishSubject
and the ReplaySubject
, check their docs for your use case).
The rx_dart
library is an extension of the Stream base classes and are much more powerful and easier to work.
Check their GitHub: https://github.com/ReactiveX/rxdart
So, all I've needed to do is replace
final StreamController<bool> streamController = StreamController<bool>();
with final StreamController<bool> streamController = StreamController<bool>.broadcast();