write method

  1. @override
void write(
  1. Object? object
)
override

Writes the string representation of object.

Converts object to a string using object.toString().

Notice that calling sink.write(null) will will write the "null" string.

Implementation

@override
void write(Object? object) {
  final str = object?.toString();
  if (str == null || str.isEmpty) return;

  // jsonEncode returns a fully escaped string wrapped in double quotes.
  // e.g., `"escaped\ntext"`
  final escaped = jsonEncode(str);
  if (escaped.length >= 2) {
    // Strip the first and last quote from the encoded string.
    _inner.write(escaped.substring(1, escaped.length - 1));
  }
}