useStreamSubscription<S> method
Subscribes to a stream and manages the subscription lifecycle.
key
: A unique string key to identify the StreamSubscription.
stream
: The stream to subscribe to.
onData
: A callback to handle incoming data events.
Returns a StreamSubscription associated with the given key.
Implementation
StreamSubscription<S> useStreamSubscription<S>({
required String key,
required Stream<S> stream,
required void Function(S event) onData,
}) {
return _getOrCreate(
key: key,
create: () => stream.listen(onData),
disposeHandler: (subscription) async => subscription.cancel()
);
}