usePlatformBrightness function

ReadonlyRef<Brightness> usePlatformBrightness()

Creates a reactive reference to the platform brightness (light/dark mode).

This automatically updates when the system theme changes.

Example:

@override
Widget Function(BuildContext) setup() {
  final brightness = usePlatformBrightness();

  final isDark = computed(() => brightness.value == Brightness.dark);

  return (context) => Text(
    'Theme: ${isDark.value ? "Dark" : "Light"}'
  );
}

Implementation

ReadonlyRef<Brightness> usePlatformBrightness() {
  return useContextRef(MediaQuery.platformBrightnessOf);
}