void finalizeChildren()

Called during the compilation phase after all the children of this node have been compiled.

This function lets the semantic node respond to all the changes to its child list for the given frame at once instead of needing to process the changes incrementally as new children are compiled.

Source

void finalizeChildren() {
  // The goal of this function is updating sawChange.
  if (_children != null) {
    for (SemanticsNode child in _children)
      child._dead = true;
  }
  if (_newChildren != null) {
    for (SemanticsNode child in _newChildren)
      child._dead = false;
  }
  bool sawChange = false;
  if (_children != null) {
    for (SemanticsNode child in _children) {
      if (child._dead) {
        if (child.parent == this) {
          // we might have already had our child stolen from us by
          // another node that is deeper in the tree.
          dropChild(child);
        }
        sawChange = true;
      }
    }
  }
  if (_newChildren != null) {
    for (SemanticsNode child in _newChildren) {
      if (child.parent != this) {
        if (child.parent != null) {
          // we're rebuilding the tree from the bottom up, so it's possible
          // that our child was, in the last pass, a child of one of our
          // ancestors. In that case, we drop the child eagerly here.
          // TODO(ianh): Find a way to assert that the same node didn't
          // actually appear in the tree in two places.
          child.parent?.dropChild(child);
        }
        assert(!child.attached);
        adoptChild(child);
        sawChange = true;
      }
    }
  }
  List<SemanticsNode> oldChildren = _children;
  _children = _newChildren;
  oldChildren?.clear();
  _newChildren = oldChildren;
  if (sawChange)
    _markDirty();
}