findWidgetElementChild method
Finds the nearest RenderWidgetElementChild ancestor in the render tree.
This method traverses up the render tree looking for a RenderWidgetElementChild which is used to pass Flutter widget constraints to WebF HTML elements.
The search stops when it either:
- Finds a RenderWidgetElementChild and returns it
- Reaches the root of the render tree
Note: RenderWidgetElementChild may sit above a RenderWidget when a WebF
element is embedded into a Flutter widget subtree (e.g., via
WebFWidgetElementChild(child: someElement.toWidget())). In that case, we
must continue traversing past RenderWidget to observe the outer Flutter
constraints.
Returns null if no RenderWidgetElementChild is found in the ancestor chain.
This is used to access parent constraints for layout calculations, allowing HTML elements to be aware of their Flutter widget container constraints for proper sizing and layout.
Implementation
RenderWidgetElementChild? findWidgetElementChild() {
RenderObject? ancestor = parent;
while (ancestor != null) {
if (ancestor is RenderWidgetElementChild) return ancestor;
ancestor = ancestor.parent;
}
return null;
}