brightnessOf static method
Resolves the effective brightness for all glass widgets in this context.
This is the single authority for brightness within the package. All glass widgets must call this instead of querying CupertinoTheme.brightnessOf or MediaQuery.platformBrightnessOf directly.
Resolution cascade (highest priority first):
- GlassThemeData.brightness — an explicit brightness override set by the developer on the nearest GlassTheme ancestor.
- CupertinoThemeData.brightness — an explicit Cupertino brightness pin (non-null only when the developer set it intentionally).
- Material Theme brightness — honours ThemeMode.light, ThemeMode.dark, and ThemeMode.system.
- MediaQuery.platformBrightnessOf — the device/OS system setting (historical default, safe fallback).
This ensures glass widgets always follow the app's intended brightness even when the device OS and app theme disagree (e.g. device is in Dark Mode but the app is pinned to Light Mode).
Implementation
static Brightness brightnessOf(BuildContext context) {
// Level 1: explicit glass-theme override.
final override = GlassTheme.maybeOf(context)?.data.brightness;
if (override != null) return override;
// Levels 2-4: framework cascade (Cupertino pin → Material → system).
return resolveGlassBrightness(context);
}