project<T> static method

List<Node<T>> project<T>({
  1. required List<Node<T>> nodes,
  2. required ViewMode mode,
})

Returns the root-level nodes to display for mode:

  • ViewMode.folder: the natural projection — keep Folders and Parents at the root; a root-level Child is dropped.
  • ViewMode.tree: the flattened projection — Folders are hidden and their contained Parents are recursively lifted to the root.

Implementation

static List<Node<T>> project<T>({
  required List<Node<T>> nodes,
  required ViewMode mode,
}) {
  switch (mode) {
    case ViewMode.tree:
      final parents = <Node<T>>[];
      _collectParents(nodes, parents);
      return parents;
    case ViewMode.folder:
      return nodes
          .where(
              (n) => n.type == NodeType.folder || n.type == NodeType.parent)
          .toList();
  }
}