attachRenderObject method

  1. @override
void attachRenderObject(
  1. Object? newSlot

Add renderObject to the render tree at the location specified by newSlot.

The default implementation of this function calls attachRenderObject recursively on each child. The RenderObjectElement.attachRenderObject override does the actual work of adding renderObject to the render tree.

The newSlot argument specifies the new value for this element's slot.


void attachRenderObject(Object? newSlot) {
  assert(_ancestorRenderObjectElement == null);
  _slot = newSlot;
  _ancestorRenderObjectElement = _findAncestorRenderObjectElement();
  assert(() {
    if (_ancestorRenderObjectElement == null) {
      FlutterError.reportError(FlutterErrorDetails(exception: FlutterError.fromParts(
          'The render object for ${toStringShort()} cannot find ancestor render object to attach to.',
          'The ownership chain for the RenderObject in question was:\n  ${debugGetCreatorChain(10)}',
          'Try wrapping your widget in a View widget or any other widget that is backed by '
          'a $RenderTreeRootElement to serve as the root of the render tree.',
    return true;
  _ancestorRenderObjectElement?.insertRenderObjectChild(renderObject, newSlot);
  final List<ParentDataElement<ParentData>> parentDataElements = _findAncestorParentDataElements();
  for (final ParentDataElement<ParentData> parentDataElement in parentDataElements) {
    _updateParentData(parentDataElement.widget as ParentDataWidget<ParentData>);