A controller with a stream that supports only one single subscriber.
If sync is true, the returned stream controller is a
SynchronousStreamController, and must be used with the care
and attention necessary to not break the Stream contract.
The controller will buffer all incoming events until the subscriber is registered.
The onPause function is called when the stream becomes
paused. onResume is called when the stream resumed.
The onListen callback is called when the stream
receives its listener and onCancel when the listener ends
its subscription. If onCancel needs to perform an asynchronous operation,
onCancel should return a future that completes when the cancel operation
is done.
If the stream is canceled before the controller needs new data the
onResume call might not be executed.
Source
factory StreamController({void onListen(),
void onPause(),
void onResume(),
onCancel(),
bool sync: false}) {
return sync
? new _SyncStreamController<T>(onListen, onPause, onResume, onCancel)
: new _AsyncStreamController<T>(onListen, onPause, onResume, onCancel);
}