collapseAll method Null safety

List<Node> collapseAll(
  1. {Node? parent}
)

Collapses all node that are children of the parent node parameter. If no parent is passed, uses the root node as the parent.

Implementation

List<Node> collapseAll({Node? parent}) {
  List<Node> _children = [];
  Iterator iter =
      parent == null ? this.children.iterator : parent.children.iterator;
  while (iter.moveNext()) {
    Node child = iter.current;
    if (child.isParent) {
      _children.add(child.copyWith(
        expanded: false,
        children: this.collapseAll(parent: child),
      ));
    } else {
      _children.add(child);
    }
  }
  return _children;
}