handlePlatformBrightnessChanged method

  1. @override
void handlePlatformBrightnessChanged ()

Called when the platform brightness changes.

The current platform brightness can be queried from a Flutter binding or from a MediaQuery widget. The latter is preferred from widgets because it causes the widget to be automatically rebuilt when the brightness changes.

final Brightness brightness = WidgetsBinding.instance.window.platformBrightness;

Querying MediaQuery directly. Preferred.
final Brightness brightness = MediaQuery.platformBrightnessOf(context);

Querying MediaQueryData.
final MediaQueryData mediaQueryData = MediaQuery.of(context);
final Brightness brightness = mediaQueryData.platformBrightness;

See Window.onPlatformBrightnessChanged.


void handlePlatformBrightnessChanged() {
  for (final WidgetsBindingObserver observer in _observers)