Skip to main content

WidgetsBinding

Struct WidgetsBinding 

Source
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

Source

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.

Source

pub fn platform_menu_delegate( self: Handle<Self>, app: &App, ) -> PlatformMenuDelegateRef

The [PlatformMenuDelegate] the app’s [PlatformMenuBar] hands its menus to: by default a DefaultPlatformMenuDelegate, which hands them to the host’s menu bar.

Source

pub fn set_platform_menu_delegate( self: Handle<Self>, app: &mut App, delegate: PlatformMenuDelegateRef, )

Replaces the [PlatformMenuDelegate], as Flutter’s platformMenuDelegate setter does.

Source

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.

Source

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.

Source

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.

Source

pub fn root_element(self: Handle<Self>, app: &App) -> Option<AnyElement>

The Element that is at the root of the element tree hierarchy.

This is initialized the first time run_app is called.

Source

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.

Source

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.

Source

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.
Source

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.

Source

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).

Source

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).

Source

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.

Source

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.

Source

pub fn handle_drag(self: Handle<Self>, app: &mut App, report: &DragReport)

Tells the observers of an external drag over a view.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn handle_platform_brightness_changed(self: Handle<Self>, app: &mut App)

Called when the platform brightness changes: tells the observers.

Source

pub fn handle_caption_style_changed(self: Handle<Self>, app: &mut App)

Called when the user’s caption style changes: tells the observers.

Source

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.

Source

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.

Source

pub fn handle_accessibility_features_changed(self: Handle<Self>, app: &mut App)

Called when the set of active accessibility features changes: tells the observers.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for WidgetsBinding

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Dart’s BindingBase.toString: <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.

Source§

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)

Runs at the start of RendererBinding::draw_frame, before layout.
Source§

fn did_draw_frame(self: Handle<Self>, app: &mut App)

Runs at the end of 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.

Source§

fn handle_app_lifecycle_state_changed( self: Handle<Self>, app: &mut App, state: AppLifecycleState, )

The override’s part of 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.

Source§

fn handle_request_app_exit( self: Handle<Self>, app: &mut App, ) -> Task<AppExitResponse> ⓘ

Answers in place of ServicesBinding::handle_request_app_exit’s own answer.

Auto Trait Implementations§

§

impl !RefUnwindSafe for WidgetsBinding

§

impl !Send for WidgetsBinding

§

impl !Sync for WidgetsBinding

§

impl !UnwindSafe for WidgetsBinding

§

impl Forget for WidgetsBinding

§

impl Freeze for WidgetsBinding
where NonZero<u32>: Freeze, PhantomData<fn() -> BuildOwner>: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, &'static ElementVTable: Freeze, *const u8 is !null: Freeze, PhantomData<Rc<dyn WidgetsBindingObserver>>: Freeze, PhantomData<(ViewId, Vec<Listener>)>: Freeze, *const RcInner<dyn PlatformMenuDelegate> is !null: Freeze, PhantomData<RcInner<dyn PlatformMenuDelegate>>: Freeze, PhantomData<(u64, Rc<dyn Fn(&mut App, TrayIconEvent)>)>: Freeze,

§

impl Move for WidgetsBinding

§

impl Unpin for WidgetsBinding
where NonZero<u32>: Unpin, Rc<Keep>: Unpin, &'static ElementVTable: Unpin, *const u8 is !null: Unpin, Rc<dyn WidgetsBindingObserver>: Unpin, Rc<dyn Fn(&mut App)>: Unpin, *const (): Unpin, Rc<dyn PlatformMenuDelegate>: Unpin, Rc<dyn Fn(&mut App, TrayIconEvent)>: Unpin,

§

impl UnsafeUnpin for WidgetsBinding

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>