findNodeByKey method

DartBlockProgramTreeNode? findNodeByKey(
  1. int key
)

Return this node if its key matches. Otherwise, perform downward traversal to find matches in the child nodes.

Implementation

DartBlockProgramTreeNode? findNodeByKey(int key) {
  if (this.key == key) {
    return this;
  } else {
    for (var child in children) {
      final foundNode = child.findNodeByKey(key);
      if (foundNode != null) {
        return foundNode;
      }
    }
  }

  return null;
}