attachToBuildOwner method

void attachToBuildOwner(
  1. RootWidget widget
)

Called by attachRootWidget to attach the provided RootWidget to the buildOwner.

This creates the rootElement, if necessary, or re-uses an existing one.

This method is rarely called directly, but it can be useful in tests to restore the element tree to a previous version by providing the RootWidget of that version (see WidgetTester.restartAndRestore for an exemplary use case).

Implementation

void attachToBuildOwner(RootWidget widget) {
  final bool isBootstrapFrame = rootElement == null;
  _readyToProduceFrames = true;
  _rootElement = widget.attach(buildOwner!, rootElement as RootElement?);
  if (isBootstrapFrame) {
    SchedulerBinding.instance.ensureVisualUpdate();
  }
}