Skip to main content

AppLifecycleListener

Struct AppLifecycleListener 

Source
pub struct AppLifecycleListener {
    pub binding: Handle<WidgetsBinding>,
    pub on_state_change: Option<Rc<dyn Fn(&mut App, AppLifecycleState)>>,
    pub on_inactive: Option<Rc<dyn Fn(&mut App)>>,
    pub on_resume: Option<Rc<dyn Fn(&mut App)>>,
    pub on_hide: Option<Rc<dyn Fn(&mut App)>>,
    pub on_show: Option<Rc<dyn Fn(&mut App)>>,
    pub on_pause: Option<Rc<dyn Fn(&mut App)>>,
    pub on_restart: Option<Rc<dyn Fn(&mut App)>>,
    pub on_exit_requested: Option<AppExitRequestCallback>,
    pub on_detach: Option<Rc<dyn Fn(&mut App)>>,
    /* private fields */
}
Expand description

A listener that can be used to listen to changes in the application lifecycle.

To listen for requests for the application to exit, and to decide whether or not the application should exit when requested, create an AppLifecycleListener and set the on_exit_requested callback.

To listen for changes in the application lifecycle state, define an on_state_change callback. See the AppLifecycleState enum for details on the various states.

The on_state_change callback is called for each state change, and the individual state transitions (on_resume, on_inactive, etc.) are also called if the state transition they represent occurs.

State changes will occur in accordance with the state machine described by AppLifecycleState.

The initial state of the state machine is the AppLifecycleState::Detached state, and the arrows describe valid state transitions.

See also:

Fields§

§binding: Handle<WidgetsBinding>

The WidgetsBinding to listen to for application lifecycle events.

Typically, this is set to WidgetsBinding::instance.

§on_state_change: Option<Rc<dyn Fn(&mut App, AppLifecycleState)>>

Called anytime the state changes, passing the new state.

§on_inactive: Option<Rc<dyn Fn(&mut App)>>

A callback that is called when the application loses input focus.

On mobile platforms, this can be during a phone call or when a system dialog is visible.

On desktop platforms, this is when all views in an application have lost input focus but at least one view of the application is still visible.

On the web, this is when the window (or tab) has lost input focus.

§on_resume: Option<Rc<dyn Fn(&mut App)>>

A callback that is called when a view in the application gains input focus.

A call to this callback indicates that the application is entering a state where it is visible, active, and accepting user input.

§on_hide: Option<Rc<dyn Fn(&mut App)>>

A callback that is called when the application is hidden.

On mobile platforms, this is usually just before the application is replaced by another application in the foreground.

On desktop platforms, this is just before the application is hidden by being minimized or otherwise hiding all views of the application.

On the web, this is just before a window (or tab) is hidden.

§on_show: Option<Rc<dyn Fn(&mut App)>>

A callback that is called when the application is shown.

On mobile platforms, this is usually just before the application replaces another application in the foreground.

On desktop platforms, this is just before the application is shown after being minimized or otherwise made to show at least one view of the application.

On the web, this is just before a window (or tab) is shown.

§on_pause: Option<Rc<dyn Fn(&mut App)>>

A callback that is called when the application is paused.

On mobile platforms, this happens right before the application is replaced by another application.

On desktop platforms and the web, this function is not called.

§on_restart: Option<Rc<dyn Fn(&mut App)>>

A callback that is called when the application is resumed after being paused.

On mobile platforms, this happens just before this application takes over as the active application.

On desktop platforms and the web, this function is not called.

§on_exit_requested: Option<AppExitRequestCallback>

A callback used to ask the application if it will allow exiting the application for cases where the exit is cancelable.

Exiting the application isn’t always cancelable, but when it is, this function will be called before exit occurs.

Responding AppExitResponse::Exit will continue termination, and responding AppExitResponse::Cancel will cancel it. If termination is not canceled, the application will immediately exit.

§on_detach: Option<Rc<dyn Fn(&mut App)>>

A callback that is called when an application has exited, and detached all host views from the engine.

This callback is only called on iOS and Android.

Implementations§

Source§

impl AppLifecycleListener

Source

pub fn debug_fill_properties( self: Handle<Self>, app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s AppLifecycleListener.debugFillProperties.

Source

pub fn new(app: &mut App) -> Ref<AppLifecycleListener>

Source

pub fn on_state_change( self: Ref<Self>, app: &mut App, on_state_change: Rc<dyn Fn(&mut App, AppLifecycleState)>, ) -> Ref<Self>

Dart AppLifecycleListener(onStateChange:).

Source

pub fn on_inactive( self: Ref<Self>, app: &mut App, on_inactive: Rc<dyn Fn(&mut App)>, ) -> Ref<Self>

Dart AppLifecycleListener(onInactive:).

Source

pub fn on_resume( self: Ref<Self>, app: &mut App, on_resume: Rc<dyn Fn(&mut App)>, ) -> Ref<Self>

Dart AppLifecycleListener(onResume:).

Source

pub fn on_hide( self: Ref<Self>, app: &mut App, on_hide: Rc<dyn Fn(&mut App)>, ) -> Ref<Self>

Dart AppLifecycleListener(onHide:).

Source

pub fn on_show( self: Ref<Self>, app: &mut App, on_show: Rc<dyn Fn(&mut App)>, ) -> Ref<Self>

Dart AppLifecycleListener(onShow:).

Source

pub fn on_pause( self: Ref<Self>, app: &mut App, on_pause: Rc<dyn Fn(&mut App)>, ) -> Ref<Self>

Dart AppLifecycleListener(onPause:).

Source

pub fn on_restart( self: Ref<Self>, app: &mut App, on_restart: Rc<dyn Fn(&mut App)>, ) -> Ref<Self>

Dart AppLifecycleListener(onRestart:).

Source

pub fn on_exit_requested( self: Ref<Self>, app: &mut App, on_exit_requested: AppExitRequestCallback, ) -> Ref<Self>

Dart AppLifecycleListener(onExitRequested:).

Source

pub fn on_detach( self: Ref<Self>, app: &mut App, on_detach: Rc<dyn Fn(&mut App)>, ) -> Ref<Self>

Dart AppLifecycleListener(onDetach:).

Source

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

Call when the listener is no longer in use.

Do not use the object after calling dispose.

Trait Implementations§

Source§

impl Debug for AppLifecycleListener

Source§

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

Formats the value using the given formatter. Read more
Source§

impl WidgetsBindingObserverObject for AppLifecycleListener

Source§

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

Source§

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

Source§

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

Source§

fn did_change_locales( self: Handle<Self>, app: &mut App, locales: Option<&[Locale]>, )

Source§

fn did_change_view_focus( self: Handle<Self>, app: &mut App, event: ViewFocusEvent, )

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

fn did_pop_route(self: Handle<Self>, app: &mut App, view: ViewId) -> bool

Source§

fn handle_start_back_gesture( self: Handle<Self>, app: &mut App, back_event: PredictiveBackEvent, ) -> bool

Source§

fn handle_update_back_gesture_progress( self: Handle<Self>, app: &mut App, back_event: PredictiveBackEvent, )

Source§

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

Source§

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

Source§

fn did_add_view(self: Handle<Self>, app: &mut App, view: &ViewRef)

Source§

fn did_remove_view(self: Handle<Self>, app: &mut App, view: ViewId)

Source§

fn did_fail_view_request( self: Handle<Self>, app: &mut App, request: RequestId, error: &ViewError, )

Source§

fn did_request_view_close( self: Handle<Self>, app: &mut App, view: ViewId, ) -> bool

Auto Trait Implementations§

§

impl !RefUnwindSafe for AppLifecycleListener

§

impl !Send for AppLifecycleListener

§

impl !Sync for AppLifecycleListener

§

impl !UnwindSafe for AppLifecycleListener

§

impl Forget for AppLifecycleListener

§

impl Freeze for AppLifecycleListener
where NonZero<u32>: Freeze, PhantomData<fn() -> WidgetsBinding>: Freeze, *const RcInner<dyn Fn(&mut App, AppLifecycleState)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AppLifecycleState)>>: Freeze, *const RcInner<dyn Fn(&mut App)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App)>>: Freeze, *const RcInner<dyn Fn(&mut App) -> Task<AppExitResponse>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App) -> Task<AppExitResponse>>>: Freeze, *const RcInner<dyn WidgetsBindingObserver> is !null: Freeze,

§

impl Move for AppLifecycleListener

§

impl Unpin for AppLifecycleListener
where NonZero<u32>: Unpin, Rc<dyn Fn(&mut App, AppLifecycleState)>: Unpin, Rc<dyn Fn(&mut App)>: Unpin, Rc<dyn Fn(&mut App) -> Task<AppExitResponse>>: Unpin, *const RcInner<dyn WidgetsBindingObserver> is !null: Unpin,

§

impl UnsafeUnpin for AppLifecycleListener
where NonZeroU32Inner: UnsafeUnpin, PhantomData<fn() -> WidgetsBinding>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AppLifecycleState)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AppLifecycleState)>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App)>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App) -> Task<AppExitResponse>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App) -> Task<AppExitResponse>>>: UnsafeUnpin, *const RcInner<dyn WidgetsBindingObserver> is !null: UnsafeUnpin,

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, 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>