listen<T> method
StreamSubscription<T>
listen<T>(
- Stream<
T> stream, - void listener(
- T it
- void onDone()?,
- void onError(
- Object error,
- StackTrace
override
Implementation
@override
StreamSubscription<T> listen<T>(
Stream<T> stream,
void Function(T it) listener, {
void Function()? onDone,
void Function(Object error, StackTrace)? onError,
}) {
final controller = StreamController<T>(sync: true);
onInit(() {
final subscription = stream.listen(controller.add, onDone: controller.close, onError: controller.addError);
onDispose(() {
subscription.cancel();
controller.close();
});
});
return controller.stream.listen(listener, onDone: onDone, onError: onError);
}