visitChildren method

  1. @override
void visitChildren(
  1. ElementVisitor visitor
)
override

Calls the argument for each child. Must be overridden by subclasses that support having children.

There is no guaranteed order in which the children will be visited, though it should be consistent over time.

Calling this during build is dangerous: the child list might still be being updated at that point, so the children might not be constructed yet, or might be old children that are going to be replaced. This method should only be called if it is provable that the children are available.

Implementation

@override
void visitChildren(ElementVisitor visitor) {
  // The toList() is to make a copy so that the underlying list can be modified by
  // the visitor:
  assert(!_childElements.values.any((Element? child) => child == null));
  _childElements.values.cast<Element>().toList().forEach(visitor);
}