attach method

RootElement attach(
  1. BuildOwner owner, [
  2. RootElement? element
])

Inflate this widget and attaches it to the provided BuildOwner.

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 WidgetsBinding.attachToBuildOwner (which is indirectly called by runApp) to bootstrap applications.

Implementation

RootElement attach(BuildOwner owner, [ RootElement? element ]) {
  if (element == null) {
    owner.lockState(() {
      element = createElement();
      assert(element != null);
      element!.assignOwner(owner);
    });
    owner.buildScope(element!, () {
      element!.mount(/* parent */ null, /* slot */ null);
    });
  } else {
    element._newWidget = this;
    element.markNeedsBuild();
  }
  return element!;
}