getParentElement function
Returns the parent of element
applying validator
and maxLevels
.
Implementation
Element? getParentElement(Element element,
{bool Function(Element parent)? validator, int maxLevels = 1000}) {
if (maxLevels < 1) return null;
for (var level = 1; level <= maxLevels; ++level) {
var parent = element.parent;
if (parent != null) {
if (validator != null) {
if (validator(parent)) {
return parent;
}
} else {
return parent;
}
element = parent;
} else {
break;
}
}
return null;
}