pub struct BuildOwner { /* private fields */ }Expand description
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::assign_owner method on the
root element of the widget tree.
Implementations§
Source§impl BuildOwner
impl BuildOwner
Sourcepub fn new(
app: &mut App,
on_build_scheduled: Option<BuildScheduledCallback>,
) -> Ref<BuildOwner>
pub fn new( app: &mut App, on_build_scheduled: Option<BuildScheduledCallback>, ) -> Ref<BuildOwner>
Creates an object that manages widgets.
This constructs a new FocusManager and registers its global input handlers via
FocusManager::register_global_handlers, which will modify static state. Callers
wishing to avoid altering this state can explicitly pass a focus manager to
with_focus_manager, Dart’s focusManager argument.
Sourcepub fn with_focus_manager(
app: &mut App,
on_build_scheduled: Option<BuildScheduledCallback>,
focus_manager: Ref<FocusManager>,
) -> Ref<BuildOwner>
pub fn with_focus_manager( app: &mut App, on_build_scheduled: Option<BuildScheduledCallback>, focus_manager: Ref<FocusManager>, ) -> Ref<BuildOwner>
Creates an object that manages widgets, with the FocusManager Dart’s focusManager
argument supplies; its global input handlers are not registered.
Sourcepub fn focus_manager(self: Handle<Self>, app: &App) -> Handle<FocusManager>
pub fn focus_manager(self: Handle<Self>, app: &App) -> Handle<FocusManager>
The object in charge of the focus tree.
Rarely used directly. Instead, consider using FocusScope::of to obtain the
FocusScopeNode for a given BuildContext.
Sourcepub fn set_focus_manager(
self: Handle<Self>,
app: &mut App,
focus_manager: Ref<FocusManager>,
)
pub fn set_focus_manager( self: Handle<Self>, app: &mut App, focus_manager: Ref<FocusManager>, )
Replaces the object in charge of the focus tree (Dart’s mutable focusManager field).
Sourcepub fn set_on_build_scheduled(
self: Handle<Self>,
app: &mut App,
callback: Option<BuildScheduledCallback>,
)
pub fn set_on_build_scheduled( self: Handle<Self>, app: &mut App, callback: Option<BuildScheduledCallback>, )
Replaces the on_build_scheduled callback.
Sourcepub fn schedule_build_for(
self: Handle<Self>,
app: &mut App,
element: AnyElement,
)
pub fn schedule_build_for( self: Handle<Self>, app: &mut App, element: AnyElement, )
Adds an element to the dirty elements list so that it will be rebuilt when
WidgetsBinding::draw_frame calls build_scope.
Sourcepub fn debug_building(self: Handle<Self>, app: &App) -> bool
pub fn debug_building(self: Handle<Self>, app: &App) -> bool
Whether this widget tree is in the build phase.
Only valid when asserts are enabled.
Sourcepub fn lock_state(
self: Handle<Self>,
app: &mut App,
callback: impl FnOnce(&mut App),
)
pub fn lock_state( self: Handle<Self>, app: &mut App, callback: impl FnOnce(&mut App), )
Establishes a scope in which calls to State::set_state are forbidden, and calls the
given callback.
This mechanism is used to ensure that, for instance, State::dispose does not call
State::set_state.
Sourcepub fn build_scope(
self: Handle<Self>,
app: &mut App,
context: AnyElement,
callback: Option<BuildScopeCallback>,
)
pub fn build_scope( self: Handle<Self>, app: &mut App, context: AnyElement, callback: Option<BuildScopeCallback>, )
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
schedule_build_for, in depth order.
This mechanism prevents build methods from transitively requiring other build methods to run, potentially causing infinite loops.
The dirty list is processed after callback returns, building all the elements that
were marked as dirty using schedule_build_for, in depth
order. If elements are marked as dirty while this method is running, they must be
deeper than the context node, and deeper than any previously-built node in this
pass.
To flush the current dirty list without performing any other work, this function can
be called with no callback. This is what the framework does each frame, in
WidgetsBinding::draw_frame.
Only one build_scope can be active at a time.
A build_scope implies a lock_state scope
as well.
Sourcepub fn global_key_count(self: Handle<Self>, app: &App) -> usize
pub fn global_key_count(self: Handle<Self>, app: &App) -> usize
The number of GlobalKey instances that are currently associated with Elements
that have been built by this build owner.
Sourcepub fn global_key_element(
self: Handle<Self>,
app: &App,
key: &GlobalKey,
) -> Option<AnyElement>
pub fn global_key_element( self: Handle<Self>, app: &App, key: &GlobalKey, ) -> Option<AnyElement>
The element registered under a global key, if any.
Sourcepub fn debug_inactive_contains(
self: Handle<Self>,
app: &App,
element: AnyElement,
) -> bool
pub fn debug_inactive_contains( self: Handle<Self>, app: &App, element: AnyElement, ) -> bool
Whether element is on the inactive list; for tests.
Sourcepub fn finalize_tree(self: Handle<Self>, app: &mut App)
pub fn finalize_tree(self: Handle<Self>, app: &mut App)
Complete the element build pass by unmounting any elements that are no longer active.
This is called by WidgetsBinding::draw_frame.
In debug mode, this also runs some sanity checks, for example checking for duplicate global keys.