flatten<T> static method
Flattens a tree of nodes into a list of FlatNodes, only including children of expanded nodes.
This produces the visible node list for virtualized rendering.
Implementation
static List<FlatNode<T>> flatten<T>({
required List<Node<T>> nodes,
required Set<String>? expandedNodeIds,
int depth = 0,
bool isRoot = true,
List<bool> ancestorIsLastFlags = const [],
}) {
final result = <FlatNode<T>>[];
// Use a mutable list for recursion to avoid spreading a new list
// at every level. Each FlatNode receives an unmodifiable snapshot.
final mutableFlags = List<bool>.of(ancestorIsLastFlags);
_flattenInto<T>(
result: result,
nodes: nodes,
expandedNodeIds: expandedNodeIds,
depth: depth,
isRoot: isRoot,
mutableFlags: mutableFlags,
);
return result;
}