visitChildrenForSemantics method

  1. @override
void visitChildrenForSemantics(
  1. RenderObjectVisitor visitor
)
override

Called when collecting the semantics of this node.

The implementation has to return the children in paint order skipping all children that are not semantically relevant (e.g. because they are invisible).

The default implementation mirrors the behavior of visitChildren (which is supposed to walk all the children).

Implementation

@override
void visitChildrenForSemantics(RenderObjectVisitor visitor) {
  // Assign stable child indices for scroll semantics (indexInParent / scrollIndex).
  // This mirrors how Flutter's scroll views wrap children in RenderIndexedSemantics.
  RenderBox? child = firstChild;
  int index = 0;
  while (child != null) {
    final RenderLayoutParentData parentData = child.parentData as RenderLayoutParentData;
    parentData.semanticsIndex = index;
    visitor(child);
    child = parentData.nextSibling;
    index++;
  }
}