BuildOwner class

Manager class for the widgets framework.

This class tracks which widgets need rebuilding, and handles other tasks that apply to widget trees as a whole, such as managing the inactive element list for the tree and triggering the "reassemble" command when necessary during hot reload when debugging.

The main build owner is typically owned by the WidgetsBinding, and is driven from the operating system along with the rest of the build/layout/paint pipeline.

Additional build owners can be built to manage off-screen widget trees.

To assign a build owner to a tree, use the RootElementMixin.assignOwner method on the root element of the widget tree.

This example shows how to build an off-screen widget tree used to measure the layout size of the rendered tree. For some use cases, the simpler Offstage widget may be a better alternative to this approach.

To create a local project with this code sample, run:
flutter create --sample=widgets.BuildOwner.1 mysample


BuildOwner({VoidCallback? onBuildScheduled, FocusManager? focusManager})
Creates an object that manages widgets.


debugBuilding bool
Whether this widget tree is in the build phase.
no setter
focusManager FocusManager
The object in charge of the focus tree.
getter/setter pair
globalKeyCount int
The number of GlobalKey instances that are currently associated with Elements that have been built by this build owner.
no setter
hashCode int
The hash code for this object.
no setterinherited
onBuildScheduled VoidCallback?
Called on each build pass when the first buildable element is marked dirty.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited


buildScope(Element context, [VoidCallback? callback]) → void
Establishes a scope for updating the widget tree, and calls the given callback, if any. Then, builds all the elements that were marked as dirty using scheduleBuildFor, in depth order.
finalizeTree() → void
Complete the element build pass by unmounting any elements that are no longer active.
lockState(VoidCallback callback) → void
Establishes a scope in which calls to State.setState are forbidden, and calls the given callback.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
reassemble(Element root) → void
Cause the entire subtree rooted at the given Element to be entirely rebuilt. This is used by development tools when the application code has changed and is being hot-reloaded, to cause the widget tree to pick up any changed implementations.
scheduleBuildFor(Element element) → void
Adds an element to the dirty elements list so that it will be rebuilt when WidgetsBinding.drawFrame calls buildScope.
toString() String
A string representation of this object.


operator ==(Object other) bool
The equality operator.