attachRenderObject method

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

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.

Implementation

@override
void attachRenderObject(Object? newSlot) {
  assert(_ancestorRenderObjectElement == null);
  _slot = newSlot;
  _ancestorRenderObjectElement = _findAncestorRenderObjectElement();
  assert(() {
    if (_ancestorRenderObjectElement == null) {
      FlutterError.reportError(FlutterErrorDetails(exception: FlutterError.fromParts(
      <DiagnosticsNode>[
        ErrorSummary(
          'The render object for ${toStringShort()} cannot find ancestor render object to attach to.',
        ),
        ErrorDescription(
          'The ownership chain for the RenderObject in question was:\n  ${debugGetCreatorChain(10)}',
        ),
        ErrorHint(
          '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>);
  }
}