mount method Null safety

  1. @override
void mount(
  1. Element? parent,
  2. Object? newSlot
)
override

Add this element to the tree in the given slot of the given parent.

The framework calls this function when a newly created element is added to the tree for the first time. Use this method to initialize state that depends on having a parent. State that is independent of the parent can more easily be initialized in the constructor.

This method transitions the element from the "initial" lifecycle state to the "active" lifecycle state.

Subclasses that override this method are likely to want to also override update, visitChildren, RenderObjectElement.insertRenderObjectChild, RenderObjectElement.moveRenderObjectChild, and RenderObjectElement.removeRenderObjectChild.

Implementations of this method should start with a call to the inherited method, as in super.mount(parent, newSlot).

Implementation

@override
void mount(Element? parent, Object? newSlot) {
  super.mount(parent, newSlot);
  assert(() {
    _debugDoingBuild = true;
    return true;
  }());
  _renderObject = (widget as RenderObjectWidget).createRenderObject(this);
  assert(!_renderObject!.debugDisposed!);
  assert(() {
    _debugDoingBuild = false;
    return true;
  }());
  assert(() {
    _debugUpdateRenderObjectOwner();
    return true;
  }());
  assert(_slot == newSlot);
  attachRenderObject(newSlot);
  _dirty = false;
}