descendants method
Recursively enumerates all nested children.
The search is depth-first in preorder. In other words, it explores the first child completely before visiting the next sibling, and the root component is visited before its children.
This ordering of descendants is considered standard in Flame: it is the
same order in which the components will normally be updated and rendered
on every game cycle. The optional parameter reversed allows iterating
through the same set of descendants in reverse order.
The Iterable produced by this method is "lazy", which means it will only traverse the component tree when required. This allows efficient chaining of various iterable methods, such as filtering, early stopping, folding, and so on -- see the documentation of the Iterable class for details. The traversal is driven by a single explicit stack of children iterators, so its cost does not grow with the depth of the tree beyond that stack.
Modifying the tree while iterating may throw a
ConcurrentModificationError, exactly as iterating over children does.
Call toList() first to iterate over a snapshot instead.
Implementation
Iterable<Component> descendants({
bool includeSelf = false,
bool reversed = false,
}) {
return _DescendantsIterable(
this,
includeSelf: includeSelf,
reversed: reversed,
);
}