flush method Null safety

Future<void> flush()

See IOSink.flush from dart:io.

Because this base class doesn't do any buffering of its own, flush always completes immediately.

Subclasses that do buffer events should override flush to complete once all events are delivered. They should also call super.flush() at the beginning of the method to throw a StateError if the sink is currently adding a stream.

Implementation

Future<void> flush() {
  if (_addingStream) throw StateError('StreamSink is bound to a stream');
  if (_closed) return Future.value();

  _addingStream = true;
  return onFlush().whenComplete(() {
    _addingStream = false;
  });
}