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