println method
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
followed by a newline.
If obj
is null
, prints 'null'
followed by a newline.
Implementation
@override
void println([Object? obj]) {
_sink.writeln(obj?.toString() ?? '');
}