findRenderObjectElement static method
Recursively searches for a RenderObjectElement in the element tree.
This utility method traverses the element tree starting from element,
returning the first RenderObjectElement found (depth-first search).
Returns null if no RenderObjectElement is found.
This is commonly used when attaching child render objects to their parents, as the child widget may not directly produce a render object (e.g., when wrapped in a StatelessWidget).
Implementation
static RenderObjectElement? findRenderObjectElement(Element element) {
if (element is RenderObjectElement) {
return element;
}
for (final child in element.children) {
final found = findRenderObjectElement(child);
if (found != null) {
return found;
}
}
return null;
}