expandToNode method Null safety

List<Node> expandToNode(
  1. String key
)

Expands a node and all of the node's ancestors so that the node is visible without the need to manually expand each node.

Implementation

List<Node> expandToNode(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: true);
      _this = _this.withUpdateNode(k, _updated);
    });
    return _this.children;
  }
  return this.children;
}