toPlainText method

String toPlainText ({bool includeSemanticsLabels: true })

Flattens the TextSpan tree into a single string.

Styles are not honored in this process. If includeSemanticsLabels is true, then the text returned will include the semanticsLabels instead of the text contents when they are present.

Implementation

String toPlainText({bool includeSemanticsLabels = true}) {
  assert(debugAssertIsValid());
  final StringBuffer buffer = StringBuffer();
  visitTextSpan((TextSpan span) {
    if (span.semanticsLabel != null && includeSemanticsLabels) {
      buffer.write(span.semanticsLabel);
    } else {
      buffer.write(span.text);
    }
    return true;
  });
  return buffer.toString();
}