closeWith method

void closeWith(
  1. HasCloser hasCloser, {
  2. void onClose()?,
})

Associates the StreamSubscription with the Closer context. You can provide an optional onClose callback function to define custom actions to be performed when the StreamSubscription is closed.

Example usage:

void initState() {
  super.initState();
  someStream.listen(processEventsData).closeWith(this);
}

Implementation

void closeWith(HasCloser hasCloser, {void Function()? onClose}) {
  hasCloser.closer.addClosable(_ClosableSubscription(this, onClose));
}