flatten<T> static method

List<FlatNode<T>> flatten<T>({
  1. required List<Node<T>> nodes,
  2. required Set<String>? expandedNodeIds,
  3. int depth = 0,
  4. bool isRoot = true,
  5. List<bool> ancestorIsLastFlags = const [],
})

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;
}