Problem Statement
What is the difference between single-subscription and broadcast streams?
Explanation
Single-subscription streams allow only one listener at a time - attempting to listen twice throws an error. They're used for streaming data that should be consumed sequentially like reading a file or processing HTTP response body. Once you listen and consume the data, it's gone - you can't replay it. Most streams are single-subscription by default including those from async* functions.
Broadcast streams allow multiple listeners simultaneously, with each listener receiving the same events. Events are sent to all current listeners when emitted, but late listeners miss events that occurred before they subscribed. Use broadcast streams for events that multiple parts of your app need to observe simultaneously, like button clicks or app lifecycle events.
Convert single-subscription to broadcast using stream.asBroadcastStream(), though this creates a new stream listening to the original. StreamController can create either type - StreamController() creates single-subscription, StreamController.broadcast() creates broadcast. Understanding this distinction prevents errors when multiple widgets try to listen to the same stream and helps choose the right stream type for your use case.
