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:
ServicesBinding::exit_applicationfor a function to call that will request that the application exits.WidgetsBindingObserver::did_request_app_exitfor the handler which this class uses to receive exit requests.WidgetsBindingObserver::did_change_app_lifecycle_statefor the handler which this class uses to receive lifecycle state changes.
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
impl AppLifecycleListener
Sourcepub fn debug_fill_properties(
self: Handle<Self>,
app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
pub fn debug_fill_properties( self: Handle<Self>, app: &App, properties: &mut DiagnosticPropertiesBuilder, )
Dart’s AppLifecycleListener.debugFillProperties.
Sourcepub fn new(app: &mut App) -> Ref<AppLifecycleListener>
pub fn new(app: &mut App) -> Ref<AppLifecycleListener>
Creates an AppLifecycleListener.
Sourcepub fn on_state_change(
self: Ref<Self>,
app: &mut App,
on_state_change: Rc<dyn Fn(&mut App, AppLifecycleState)>,
) -> Ref<Self>
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:).
Sourcepub fn on_inactive(
self: Ref<Self>,
app: &mut App,
on_inactive: Rc<dyn Fn(&mut App)>,
) -> Ref<Self>
pub fn on_inactive( self: Ref<Self>, app: &mut App, on_inactive: Rc<dyn Fn(&mut App)>, ) -> Ref<Self>
Dart AppLifecycleListener(onInactive:).
Sourcepub fn on_resume(
self: Ref<Self>,
app: &mut App,
on_resume: Rc<dyn Fn(&mut App)>,
) -> Ref<Self>
pub fn on_resume( self: Ref<Self>, app: &mut App, on_resume: Rc<dyn Fn(&mut App)>, ) -> Ref<Self>
Dart AppLifecycleListener(onResume:).
Sourcepub fn on_hide(
self: Ref<Self>,
app: &mut App,
on_hide: Rc<dyn Fn(&mut App)>,
) -> Ref<Self>
pub fn on_hide( self: Ref<Self>, app: &mut App, on_hide: Rc<dyn Fn(&mut App)>, ) -> Ref<Self>
Dart AppLifecycleListener(onHide:).
Sourcepub fn on_show(
self: Ref<Self>,
app: &mut App,
on_show: Rc<dyn Fn(&mut App)>,
) -> Ref<Self>
pub fn on_show( self: Ref<Self>, app: &mut App, on_show: Rc<dyn Fn(&mut App)>, ) -> Ref<Self>
Dart AppLifecycleListener(onShow:).
Sourcepub fn on_pause(
self: Ref<Self>,
app: &mut App,
on_pause: Rc<dyn Fn(&mut App)>,
) -> Ref<Self>
pub fn on_pause( self: Ref<Self>, app: &mut App, on_pause: Rc<dyn Fn(&mut App)>, ) -> Ref<Self>
Dart AppLifecycleListener(onPause:).
Sourcepub fn on_restart(
self: Ref<Self>,
app: &mut App,
on_restart: Rc<dyn Fn(&mut App)>,
) -> Ref<Self>
pub fn on_restart( self: Ref<Self>, app: &mut App, on_restart: Rc<dyn Fn(&mut App)>, ) -> Ref<Self>
Dart AppLifecycleListener(onRestart:).
Sourcepub fn on_exit_requested(
self: Ref<Self>,
app: &mut App,
on_exit_requested: AppExitRequestCallback,
) -> Ref<Self>
pub fn on_exit_requested( self: Ref<Self>, app: &mut App, on_exit_requested: AppExitRequestCallback, ) -> Ref<Self>
Dart AppLifecycleListener(onExitRequested:).