WidgetsBindingObserver class abstract mixin

Interface for classes that register with the Widgets layer binding.

This can be used by any class, not just widgets. It provides an interface which is used by WidgetsBinding.addObserver and WidgetsBinding.removeObserver to notify objects of changes in the environment, such as changes to the device metrics or accessibility settings. It is used to implement features such as MediaQuery.

This class can be extended directly, or mixed in, to get default behaviors for all of the handlers. Alternatively it can be used with the implements keyword, in which case all the handlers must be implemented (and the analyzer will list those that have been omitted).

To start receiving notifications, call WidgetsBinding.instance.addObserver with a reference to the object implementing the WidgetsBindingObserver interface. To avoid memory leaks, call WidgetsBinding.instance.removeObserver to unregister the object when it reaches the end of its lifecycle.

This sample shows how to implement parts of the State and WidgetsBindingObserver protocols necessary to react to application lifecycle messages. See didChangeAppLifecycleState.

To respond to other notifications, replace the didChangeAppLifecycleState method in this example with other methods from this class.

link

To create a local project with this code sample, run:
flutter create --sample=widgets.WidgetsBindingObserver.1 mysample

Implementers

Constructors

WidgetsBindingObserver()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

didChangeAccessibilityFeatures() → void
Called when the system changes the set of currently active accessibility features.
didChangeAppLifecycleState(AppLifecycleState state) → void
Called when the system puts the app in the background or returns the app to the foreground.
didChangeLocales(List<Locale>? locales) → void
Called when the system tells the app that the user's locale has changed. For example, if the user changes the system language settings.
didChangeMetrics() → void
Called when the application's dimensions change. For example, when a phone is rotated.
didChangePlatformBrightness() → void
Called when the platform brightness changes.
didChangeTextScaleFactor() → void
Called when the platform's text scale factor changes.
didChangeViewFocus(ViewFocusEvent event) → void
Called whenever the PlatformDispatcher receives a notification that the focus state on a view has changed.
didHaveMemoryPressure() → void
Called when the system is running low on memory.
didPopRoute() Future<bool>
Called when the system tells the app to pop the current route, such as after a system back button press or back gesture.
didPushRoute(String route) Future<bool>
Called when the host tells the application to push a new route onto the navigator.
didPushRouteInformation(RouteInformation routeInformation) Future<bool>
Called when the host tells the application to push a new RouteInformation and a restoration state onto the router.
didRequestAppExit() Future<AppExitResponse>
Called when a request is received from the system to exit the application.
handleCancelBackGesture() → void
Called when a predictive back gesture is canceled, indicating that no navigation should occur.
handleCommitBackGesture() → void
Called when a predictive back gesture is finished successfully, indicating that the current route should be popped.
handleStartBackGesture(PredictiveBackEvent backEvent) bool
Called at the start of a predictive back gesture.
handleUpdateBackGestureProgress(PredictiveBackEvent backEvent) → void
Called when a predictive back gesture moves.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited