extractTextFromSpan static method

  1. @visibleForTesting
String extractTextFromSpan(
  1. InlineSpan span
)

Extracts all text content from a InlineSpan tree.

Traverses the entire tree and concatenates text from all TextSpan nodes. WidgetSpan nodes are skipped as they contain no text content.

Implementation

@visibleForTesting
static String extractTextFromSpan(InlineSpan span) {
  final buffer = StringBuffer();
  final List<InlineSpan> stack = [span];
  while (stack.isNotEmpty) {
    final current = stack.removeLast();
    if (current is TextSpan) {
      if (current.text != null) buffer.write(current.text);
      if (current.children != null && current.children!.isNotEmpty) {
        for (int i = current.children!.length - 1; i >= 0; i--) {
          stack.add(current.children![i]);
        }
      }
    }
    // WidgetSpan has no text — skip.
  }
  return buffer.toString();
}