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.

Some locations in the tree are not backed by a render object. In those cases, this getter returns null. This can happen, if the element is located outside of a View since only the element subtree rooted in a view has a render tree associated with it.

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 {
      current = current.renderObjectAttachingChild;
    }
  }
  return null;
}