1. override
RenderObject ancestorRenderObjectOfType(TypeMatcher matcher)

Returns the RenderObject object of the nearest ancestor RenderObjectWidget widget that matches the given TypeMatcher.

This should not be used from build methods, because the build context will not be rebuilt if the value that would be returned by this method changes. In general, inheritFromWidgetOfExactType is more appropriate for such cases. This method is useful only in esoteric cases where a widget needs to cause an ancestor to change its layout or paint behavior. For example, it is used by Material so that InkWell widgets can trigger the ink splash on the Material's actual render object.

Calling this method is relatively expensive (O(N) in the depth of the tree). Only call this method if the distance from this widget to the desired ancestor is known to be small and bounded.

Source

@override
RenderObject ancestorRenderObjectOfType(TypeMatcher matcher) {
  Element ancestor = _parent;
  while (ancestor != null) {
    if (ancestor is RenderObjectElement && matcher.check(ancestor.renderObject))
      break;
    ancestor = ancestor._parent;
  }
  RenderObjectElement renderObjectAncestor = ancestor;
  return renderObjectAncestor?.renderObject;
}