valueToString method Null safety

  1. @override
String valueToString(
  1. {TextTreeConfiguration? parentConfiguration}

Returns a string representation of the property value.

Subclasses should override this method instead of toDescription to customize how property values are converted to strings.

Overriding this method ensures that behavior controlling how property values are decorated to generate a nice toDescription are consistent across all implementations. Debugging tools may also choose to use valueToString directly instead of toDescription.

parentConfiguration specifies how the parent is rendered as text art. For example, if the parent places all properties on one line, the value of the property should be displayed without line breaks if possible.


String valueToString({ TextTreeConfiguration? parentConfiguration }) {
  String? text = _description ?? value;
  if (parentConfiguration != null &&
      !parentConfiguration.lineBreakProperties &&
      text != null) {
    // Escape linebreaks in multiline strings to avoid confusing output when
    // the parent of this node is trying to display all properties on the same
    // line.
    text = text.replaceAll('\n', r'\n');

  if (quoted && text != null) {
    // An empty value would not appear empty after being surrounded with
    // quotes so we have to handle this case separately.
    if (ifEmpty != null && text.isEmpty)
      return ifEmpty!;
    return '"$text"';
  return text.toString();