collapseToNode method
Collapses a node and all of the node's ancestors without the need to manually collapse each node.
Implementation
List<Node> collapseToNode(String key) {
List<String> _ancestors = [];
String _currentKey = key;
_ancestors.add(_currentKey);
Node? _parent = this.getParent(_currentKey);
if (_parent != null) {
while (_parent!.key != _currentKey) {
_currentKey = _parent.key;
_ancestors.add(_currentKey);
_parent = this.getParent(_currentKey);
}
TreeViewController _this = this;
_ancestors.forEach((String k) {
Node _node = _this.getNode(k)!;
Node _updated = _node.copyWith(expanded: false);
_this = _this.withUpdateNode(k, _updated);
});
return _this.children;
}
return this.children;
}