debugExpectsRenderObjectForSlot method

  1. @override
bool debugExpectsRenderObjectForSlot(
  1. Object? slot
)
override

Whether the child in the provided slot (or one of its descendants) must insert a RenderObject into its ancestor RenderObjectElement by calling RenderObjectElement.insertRenderObjectChild on it.

This method is used to define non-rendering zones in the element tree (see WidgetsBinding for an explanation of rendering and non-rendering zones):

Most branches of the Element tree are expected to eventually insert a RenderObject into their RenderObjectElement ancestor to construct the render tree. However, there is a notable exception: an Element may expect that the occupant of a certain child slot creates a new independent render tree and therefore is not allowed to insert a render object into the existing render tree. Those elements must return false from this method for the slot in question to signal to the child in that slot that it must not call RenderObjectElement.insertRenderObjectChild on its ancestor.

As an example, the element backing the ViewAnchor returns false from this method for the ViewAnchor.view slot to enforce that it is occupied by e.g. a View widget, which will ultimately bootstrap a separate render tree for that view. Another example is the ViewCollection widget, which returns false for all its slots for the same reason.

Overriding this method is not common, as elements behaving in the way described above are rare.

Implementation

@override
// There is no ancestor RenderObjectElement that the render object could be attached to.
bool debugExpectsRenderObjectForSlot(Object? slot) => false;