collapseAll method

void collapseAll()

Collapses all nodes.

This collapses every single node of the data structure, meaning that only the upper root nodes will be in the displayNodes list.

notifyListeners is called to notify all registered listeners.

See also:

Implementation

void collapseAll() {
  final rootNodes =
      _displayNodes.where((node) => node.treeDepth == 0 && !node.isCollapsed);
  final collapsedNodes = List<NodeViewModelState>.from(_displayNodes);
  for (final node in rootNodes) {
    final nodeIndex = collapsedNodes.indexOf(node) + 1;
    final children = _visibleChildrenCount(node) - 1;
    collapsedNodes.removeRange(nodeIndex, nodeIndex + children);
  }

  for (final node in _allNodes) {
    node.collapse();
  }
  _displayNodes = collapsedNodes;
  notifyListeners();
}