capture static method

RawTree? capture(
  1. Rect viewport
)

Walk the live semantics tree.

Implementation

static RawTree? capture(Rect viewport) {
  _ensureRetained();
  if (!_safeFlush()) return null;
  final owner = WidgetsBinding.instance.pipelineOwner.semanticsOwner;
  final root = owner?.rootSemanticsNode;
  if (root == null) return null;

  final dpr = WidgetsBinding
          .instance.platformDispatcher.implicitView?.devicePixelRatio ??
      1.0;

  final out = <RawNode>[];

  void visit(
      SemanticsNode node, int parentIndex, int siblingIndex, int depth) {
    final isRoot = node.id == 0;
    final data = node.getSemanticsData();
    if (!isRoot && data.identifier == kEmbedSelfSemanticsIdentifier) {
      return;
    }
    var myIndex = parentIndex;
    if (!isRoot) {
      out.add(RawNode(
        rawId: node.id,
        data: data,
        bounds: _rectInRoot(node, dpr),
        parentIndex: parentIndex,
        siblingIndex: siblingIndex,
        depth: depth,
      ));
      myIndex = out.length - 1;
    }
    var childSib = 0;
    node.visitChildren((c) {
      visit(c, myIndex, childSib, depth + 1);
      childSib++;
      return true;
    });
  }

  visit(root, -1, 0, 0);
  final interest = _glyphInterest(out, viewport);
  final glyphs = GlyphHintCollector.collect(
    interest: interest,
    dpr: dpr,
    selfIdentifier: kEmbedSelfSemanticsIdentifier,
  );
  return RawTree(
    nodes: out,
    viewport: viewport,
    overlays: _findOverlays(out),
    glyphs: glyphs,
    // An aborted / failed walk collected nothing: then nothing is covered.
    glyphInterest: glyphs.isEmpty ? const [] : interest,
  );
}