findOne method
Find one node matching this query inside another node.
Implementation
T? findOne(Node root) {
// check root's children first...
for (var child in root.children) {
// return matching child if we find one
if (child.runtimeType == T && matches(child as T)) {
return child;
}
}
// then check root's grandchildren and beyond
for (var child in root.children) {
// return matching child if we find one
var match = findOne(child);
if (match != null) {
return match;
}
}
// return nothing if we haven't found anything
return null;
}