textSnapshot method

List<Map<String, dynamic>> textSnapshot()

Every piece of text actually painted, with where it sits.

Reads RenderParagraph, so it sees what the user sees regardless of which widget produced it — a screen assembled by a runtime that attaches no metadata still answers.

Implementation

List<Map<String, dynamic>> textSnapshot() {
  final root = _captureRenderBox();
  if (root == null) return const <Map<String, dynamic>>[];
  final out = <Map<String, dynamic>>[];
  void visit(RenderObject ro) {
    if (ro is RenderParagraph && ro.hasSize && ro.attached) {
      final text = ro.text.toPlainText().trim();
      if (text.isNotEmpty) {
        final rect = MatrixUtils.transformRect(
          ro.getTransformTo(root),
          Offset.zero & ro.size,
        );
        out.add(<String, dynamic>{
          'type': 'text',
          'text': text,
          'rect': <double>[rect.left, rect.top, rect.width, rect.height],
        });
      }
    }
    ro.visitChildren(visit);
  }

  visit(root);
  return out;
}