valueToString method Null safety

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

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.

Implementation

@override
String valueToString({TextTreeConfiguration? parentConfiguration}) {
  if (value == null)
    return value.toString();

  if (value!.isEmpty)
    return ifEmpty ?? '[]';

  final Iterable<String> formattedValues = value!.map((T v) {
    if (T == double && v is double) {
      return debugFormatDouble(v);
    } else {
      return v.toString();
    }
  });

  if (parentConfiguration != null && !parentConfiguration.lineBreakProperties) {
    // Always display the value as a single line and enclose the iterable
    // value in brackets to avoid ambiguity.
    return '[${formattedValues.join(', ')}]';
  }

  return formattedValues.join(_isSingleLine(style) ? ', ' : '\n');
}