why does this Dart broadcast stream not accept multiple listen calls why does this Dart broadcast stream not accept multiple listen calls dart dart

why does this Dart broadcast stream not accept multiple listen calls


The getter onBark invokes asBroadcastStream a second time on the _barkController.stream. The newly created broadcast-stream will try to bind to the _barkController.stream but will fail because there is already a listener.

So yes: broadcast streams may have multiple listeners, but the asBroadcastStream method must not be invoked multiple times on a single-subscription stream.

One solution is to cache the result of your first asBroadcastStream.