renderObject property

RenderObject? renderObject

The render object at (or below) this location in the tree.

If this object is a RenderObjectElement, the render object is the one at this location in the tree. Otherwise, this getter will walk down the tree until it finds a RenderObjectElement.

Implementation

RenderObject? get renderObject {
  Element? current = this;
  while (current != null) {
    if (current._lifecycleState == _ElementLifecycle.defunct) {
      break;
    } else if (current is RenderObjectElement) {
      return current.renderObject;
    } else {
      Element? next;
      current.visitChildren((Element child) {
        assert(next == null);  // This verifies that there's only one child.
        next = child;
      });
      current = next;
    }
  }
  return null;
}