pub struct WidgetsBinding { /* private fields */ }Expand description
The glue between the widgets layer and the Flutter engine.
The WidgetsBinding manages a single Element tree rooted at
root_element. This element tree is created by
attach_root_widget, and its build is scheduled onto the
renderer’s frame: the tree is built before the render tree is laid out and painted, and
finalized after.
Implementations§
Source§impl WidgetsBinding
impl WidgetsBinding
Sourcepub fn instance(app: &mut App) -> Handle<WidgetsBinding>
pub fn instance(app: &mut App) -> Handle<WidgetsBinding>
The current WidgetsBinding, created on first use (Flutter’s
WidgetsFlutterBinding.ensureInitialized).
Creating it creates the renderer, gesture, and scheduler bindings below it.
The [PlatformMenuDelegate] the app’s [PlatformMenuBar] hands its menus to: by default
a DefaultPlatformMenuDelegate, which hands them to the host’s menu bar.
Replaces the [PlatformMenuDelegate], as Flutter’s platformMenuDelegate setter does.
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 build_owner(self: Handle<Self>, app: &App) -> Handle<BuildOwner>
pub fn build_owner(self: Handle<Self>, app: &App) -> Handle<BuildOwner>
The BuildOwner in charge of executing the build pipeline for the widget tree
rooted at this binding.
Sourcepub fn debug_did_send_first_frame_event(self: Handle<Self>, app: &App) -> bool
pub fn debug_did_send_first_frame_event(self: Handle<Self>, app: &App) -> bool
Whether a frame has been drawn and sent to the host: Dart’s
debugDidSendFirstFrameEvent. Until then a dump finds no tree, or a tree not built yet.
Sourcepub fn root_element(self: Handle<Self>, app: &App) -> Option<AnyElement>
pub fn root_element(self: Handle<Self>, app: &App) -> Option<AnyElement>
Sourcepub fn ready_to_produce_frames(self: Handle<Self>, app: &App) -> bool
pub fn ready_to_produce_frames(self: Handle<Self>, app: &App) -> bool
Whether the binding is ready to produce frames: Flutter’s framesEnabled override
waits for the root widget.
Sourcepub fn schedule_attach_root_widget(
self: Handle<Self>,
app: &mut App,
root_widget: WidgetRef,
)
pub fn schedule_attach_root_widget( self: Handle<Self>, app: &mut App, root_widget: WidgetRef, )
Schedules a Timer for attaching the root widget.
This is called by run_app to configure the widget tree. Consider using
attach_root_widget if you want to build the widget tree
synchronously.
Sourcepub fn attach_root_widget(
self: Handle<Self>,
app: &mut App,
root_widget: WidgetRef,
)
pub fn attach_root_widget( self: Handle<Self>, app: &mut App, root_widget: WidgetRef, )
Takes a widget and attaches it to the root_element, creating
it if necessary.
This is called by run_app to configure the widget tree.
See also:
run_app, which bootstraps the widget tree.
Sourcepub fn attach_to_build_owner(
self: Handle<Self>,
app: &mut App,
widget: RootWidget,
)
pub fn attach_to_build_owner( self: Handle<Self>, app: &mut App, widget: RootWidget, )
Called by attach_root_widget to attach the provided
RootWidget to the build_owner.
This creates the root_element, 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.
Sourcepub fn add_observer(
self: Handle<Self>,
app: &mut App,
observer: WidgetsBindingObserverRef,
)
pub fn add_observer( self: Handle<Self>, app: &mut App, observer: WidgetsBindingObserverRef, )
Registers the given object as a binding observer. Binding observers are notified when various application events occur, for example when the system locale changes. Generally, one widget in the widget tree registers itself as a binding observer, and converts the system state into inherited widgets.
The observer is removed again with the same Rc (Dart’s Set.remove by identity).
Sourcepub fn remove_observer(
self: Handle<Self>,
app: &mut App,
observer: &WidgetsBindingObserverRef,
) -> bool
pub fn remove_observer( self: Handle<Self>, app: &mut App, observer: &WidgetsBindingObserverRef, ) -> bool
Unregisters the given observer. This should be used sparingly as it is relatively expensive (O(N) in the number of registered observers).
Sourcepub fn handle_text_scale_factor_changed(self: Handle<Self>, app: &mut App)
pub fn handle_text_scale_factor_changed(self: Handle<Self>, app: &mut App)
Called when the platform’s text scale factor changes: tells the observers.
Sourcepub fn handle_view_focus_changed(
self: Handle<Self>,
app: &mut App,
event: ViewFocusEvent,
)
pub fn handle_view_focus_changed( self: Handle<Self>, app: &mut App, event: ViewFocusEvent, )
Notifies observers that the platform focus of a view has changed.
Sourcepub fn handle_drag(self: Handle<Self>, app: &mut App, report: &DragReport)
pub fn handle_drag(self: Handle<Self>, app: &mut App, report: &DragReport)
Tells the observers of an external drag over a view.
Sourcepub fn handle_clipboard_event(
self: Handle<Self>,
app: &mut App,
event: ClipboardEvent,
)
pub fn handle_clipboard_event( self: Handle<Self>, app: &mut App, event: ClipboardEvent, )
The user copied, cut or pasted through the platform’s own command: its intent goes to the
primary focus, as EditableTextState.performSelector sends a macOS selector’s, while the
event is the clipboard (Clipboard::handle_event), so a paste reads what the user
pasted. No Flutter counterpart: its engines paste into a text field through its text
input connection.
Sourcepub fn handle_edit_command(
self: Handle<Self>,
app: &mut App,
command: EditCommand,
)
pub fn handle_edit_command( self: Handle<Self>, app: &mut App, command: EditCommand, )
The user chose an edit command from the platform’s own Edit menu: the command’s text editing intent goes to the primary focus, as a key’s shortcut sends it. No Flutter counterpart: Flutter’s macOS embedder sends the command to its text input plugin.
Sourcepub fn add_tray_icon_listener(
self: Handle<Self>,
app: &mut App,
icon: TrayIconId,
listener: TrayIconListener,
)
pub fn add_tray_icon_listener( self: Handle<Self>, app: &mut App, icon: TrayIconId, listener: TrayIconListener, )
Has listener hear the events of the tray icon icon, in place of whatever heard them
before: a PlatformTrayIcon’s
icon, or one the app added itself. No Flutter counterpart: Flutter has no tray.
Sourcepub fn remove_tray_icon_listener(
self: Handle<Self>,
app: &mut App,
icon: TrayIconId,
)
pub fn remove_tray_icon_listener( self: Handle<Self>, app: &mut App, icon: TrayIconId, )
Stops the events of the tray icon icon reaching its listener.
Sourcepub fn handle_tray_icon_event(
self: Handle<Self>,
app: &mut App,
icon: TrayIconId,
event: TrayIconEvent,
)
pub fn handle_tray_icon_event( self: Handle<Self>, app: &mut App, icon: TrayIconId, event: TrayIconEvent, )
Something happened to the tray icon icon, as the host reports it: its listener hears it,
and nothing does when it has none.
Sourcepub fn handle_platform_brightness_changed(self: Handle<Self>, app: &mut App)
pub fn handle_platform_brightness_changed(self: Handle<Self>, app: &mut App)
Called when the platform brightness changes: tells the observers.
Sourcepub fn handle_caption_style_changed(self: Handle<Self>, app: &mut App)
pub fn handle_caption_style_changed(self: Handle<Self>, app: &mut App)
Called when the user’s caption style changes: tells the observers.
Sourcepub fn handle_locale_changed(self: Handle<Self>, app: &mut App)
pub fn handle_locale_changed(self: Handle<Self>, app: &mut App)
Called when the system locale changes.
Calls dispatch_locales_changed to notify the
binding observers.
This method exposes notifications from PlatformDispatcher.onLocaleChanged.
Sourcepub fn dispatch_locales_changed(
self: Handle<Self>,
app: &mut App,
locales: Option<&[Locale]>,
)
pub fn dispatch_locales_changed( self: Handle<Self>, app: &mut App, locales: Option<&[Locale]>, )
Notify all the observers that the locale has changed (using
WidgetsBindingObserver::did_change_locales), giving them the locales argument.
This is called by handle_locale_changed when the
PlatformDispatcher.onLocaleChanged notification is received.
Sourcepub fn handle_accessibility_features_changed(self: Handle<Self>, app: &mut App)
pub fn handle_accessibility_features_changed(self: Handle<Self>, app: &mut App)
Called when the set of active accessibility features changes: tells the observers.
Sourcepub fn handle_pop_route(self: Handle<Self>, app: &mut App, view: ViewId) -> bool
pub fn handle_pop_route(self: Handle<Self>, app: &mut App, view: ViewId) -> bool
Called when the user asks to go back in view: asks each observer in turn and stops at
the first that says it went back.
Answers whether any of them did. When none did there was nothing left to go back to in the view, and the host does whatever the platform does without the application.
Sourcepub fn handle_start_back_gesture(
self: Handle<Self>,
app: &mut App,
back_event: PredictiveBackEvent,
) -> bool
pub fn handle_start_back_gesture( self: Handle<Self>, app: &mut App, back_event: PredictiveBackEvent, ) -> bool
Called when a predictive back gesture starts: asks every observer whether it handles the gesture, and keeps each that says it does as the one the rest of the gesture goes to.
Answers whether any observer handles it. Dart’s _handleStartBackGesture, which
SystemChannels.backGesture calls.
Sourcepub fn handle_update_back_gesture_progress(
self: Handle<Self>,
app: &mut App,
back_event: PredictiveBackEvent,
)
pub fn handle_update_back_gesture_progress( self: Handle<Self>, app: &mut App, back_event: PredictiveBackEvent, )
Called when a predictive back gesture moves: tells the observers that handle it.
Dart’s _handleUpdateBackGestureProgress.
Sourcepub fn handle_commit_back_gesture(
self: Handle<Self>,
app: &mut App,
view: ViewId,
) -> bool
pub fn handle_commit_back_gesture( self: Handle<Self>, app: &mut App, view: ViewId, ) -> bool
Called when a predictive back gesture in view finishes successfully: tells the
observers that handle it, or, when none does, goes back in view as Back does
(handle_pop_route).
Answers whether the application handled it; false means none of the observers
handled the gesture and nothing went back, and the host does what the platform does
without the application, as after handle_pop_route. Dart’s
_handleCommitBackGesture.
Sourcepub fn handle_cancel_back_gesture(self: Handle<Self>, app: &mut App)
pub fn handle_cancel_back_gesture(self: Handle<Self>, app: &mut App)
Called when a predictive back gesture is canceled: tells the observers that handle it.
Dart’s _handleCancelBackGesture.
Sourcepub fn is_root_widget_attached(self: Handle<Self>, app: &App) -> bool
pub fn is_root_widget_attached(self: Handle<Self>, app: &App) -> bool
Whether the root_element has been initialized.
This will be false until run_app is called (or WidgetTester.pumpWidget is
called in the context of a TestWidgetsFlutterBinding).
Trait Implementations§
Source§impl Default for WidgetsBinding
impl Default for WidgetsBinding
Source§impl Display for WidgetsBinding
impl Display for WidgetsBinding
Source§impl RendererBindingOverridesObject for WidgetsBinding
Flutter’s WidgetsBinding.drawFrame: build the dirty widgets, let the renderer draw,
then unmount what fell out of the tree.
impl RendererBindingOverridesObject for WidgetsBinding
Flutter’s WidgetsBinding.drawFrame: build the dirty widgets, let the renderer draw,
then unmount what fell out of the tree.
Source§fn did_handle_metrics_changed(self: Handle<Self>, app: &mut App)
fn did_handle_metrics_changed(self: Handle<Self>, app: &mut App)
WidgetsBinding.handleMetricsChanged after super: tells the observers.
Source§fn will_draw_frame(self: Handle<Self>, app: &mut App)
fn will_draw_frame(self: Handle<Self>, app: &mut App)
RendererBinding::draw_frame, before layout.Source§fn did_draw_frame(self: Handle<Self>, app: &mut App)
fn did_draw_frame(self: Handle<Self>, app: &mut App)
RendererBinding::draw_frame, after compositing.Source§impl SchedulerBindingOverridesObject for WidgetsBinding
Flutter’s WidgetsBinding override of handleAppLifecycleStateChanged, which tells every
observer after the scheduler’s own body has run.
impl SchedulerBindingOverridesObject for WidgetsBinding
Flutter’s WidgetsBinding override of handleAppLifecycleStateChanged, which tells every
observer after the scheduler’s own body has run.
Source§fn handle_app_lifecycle_state_changed(
self: Handle<Self>,
app: &mut App,
state: AppLifecycleState,
)
fn handle_app_lifecycle_state_changed( self: Handle<Self>, app: &mut App, state: AppLifecycleState, )
SchedulerBinding::handle_app_lifecycle_state_changed, which
runs after the scheduler’s own, as Dart’s calls super first.Source§impl ServicesBindingOverridesObject for WidgetsBinding
Flutter’s WidgetsBinding override of handleRequestAppExit, which asks every observer,
each once the one before it has answered.
impl ServicesBindingOverridesObject for WidgetsBinding
Flutter’s WidgetsBinding override of handleRequestAppExit, which asks every observer,
each once the one before it has answered.
Source§fn handle_request_app_exit(
self: Handle<Self>,
app: &mut App,
) -> Task<AppExitResponse> ⓘ
fn handle_request_app_exit( self: Handle<Self>, app: &mut App, ) -> Task<AppExitResponse> ⓘ
ServicesBinding::handle_request_app_exit’s own answer.