handlePlatformBrightnessChanged method

  1. @override
void handlePlatformBrightnessChanged()
override

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.

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

link
final Brightness brightness = WidgetsBinding.instance.platformDispatcher.platformBrightness;

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

See dart:ui.PlatformDispatcher.onPlatformBrightnessChanged.

Implementation

@override
void handlePlatformBrightnessChanged() {
  super.handlePlatformBrightnessChanged();
  for (final WidgetsBindingObserver observer in _observers) {
    observer.didChangePlatformBrightness();
  }
}