getNode<T> method Null safety

Node<T>? getNode<T>(
  1. String key,
  2. {Node? parent}
)

Gets the node that has a key value equal to the specified key.

Implementation

Node<T>? getNode<T>(String key, {Node? parent}) {
  Node<T>? _found;
  List<Node> _children = parent == null ? this.children : parent.children;
  Iterator iter = _children.iterator;
  while (iter.moveNext()) {
    Node child = iter.current;
    if (child.key == key) {
      _found = child as Node<T>;
      break;
    } else {
      if (child.isParent) {
        _found = this.getNode<T>(key, parent: child);
        if (_found != null) {
          break;
        }
      }
    }
  }
  return _found;
}