visitElementOrNull<T extends Element> method
Returns the first T with filter below this BuildContext, or null.
If last is true, then it will return the last Element found.
Visiting last is O(N), avoid using last = true.
Implementation
T? visitElementOrNull<T extends Element>({
bool last = false,
bool Function(T element)? filter,
}) {
T? found;
void visit(Element element) {
if (element is T) {
if (filter?.call(element) ?? true) {
found = element;
if (!last) return;
}
}
element.visitChildren(visit);
}
visitChildElements(visit);
return found;
}