attachToRenderTree method

RenderObjectToWidgetElement<T> attachToRenderTree (
  1. BuildOwner owner,
  2. [RenderObjectToWidgetElement<T> element]
)

Inflate this widget and actually set the resulting RenderObject as the child of container.

If element is null, this function will create a new element. Otherwise, the given element will have an update scheduled to switch to this widget.

Used by runApp to bootstrap applications.

Implementation

RenderObjectToWidgetElement<T> attachToRenderTree(BuildOwner owner, [ RenderObjectToWidgetElement<T> element ]) {
  if (element == null) {
    owner.lockState(() {
      element = createElement();
      assert(element != null);
      element.assignOwner(owner);
    });
    owner.buildScope(element, () {
      element.mount(null, null);
    });
    // This is most likely the first time the framework is ready to produce
    // a frame. Ensure that we are asked for one.
    SchedulerBinding.instance.ensureVisualUpdate();
  } else {
    element._newWidget = this;
    element.markNeedsBuild();
  }
  return element;
}