print method

  1. @override
void print(
  1. Object? obj
)
override

An abstract interface representing a stream for formatted text output.

This is analogous to Java’s PrintStream, and provides utility methods for printing values with or without newlines, flushing buffered content, and closing the stream.

Implementations of this interface can print to stdout, files, memory, or any other sink that supports basic text streaming.


📦 Example Usage:

class ConsolePrintStream implements PrintStream {
  @override
  void print(Object? obj) => stdout.print(obj ?? 'null');

  @override
  void println(Object? obj) => stdout.println(obj ?? 'null');

  @override
  void newline() => stdout.println();

  @override
  void flush() {} // No-op for stdout

  @override
  Future<void> close() async {} // Nothing to close
}

final stream = ConsolePrintStream();
stream.print('Hello');
stream.println(' World');
stream.newline();
await stream.close();

Prints the string representation of obj to the stream without a newline.

If obj is null, prints 'null'.

Implementation

@override
void print(Object? obj) {
  _sink.write(obj?.toString() ?? '');
}