resolveGlassBrightness function
Resolves the effective brightness for glass widgets.
Three-level cascade (highest priority first):
-
External resolver — a
Brightness? Function(BuildContext)callback registered via LiquidGlassWidgets.wrap'sbrightnessResolverparameter. MaterialApp users passTheme.maybeBrightnessOfhere. This correctly honours ThemeMode.light / ThemeMode.dark / ThemeMode.system without requiring this package to importflutter/material.dart.If no resolver is registered (pure CupertinoApp or CupertinoApp-only users who have no Material tree), this level returns null and is skipped.
-
CupertinoThemeData.brightness — an explicit developer Cupertino pin (non-null only when the developer set it intentionally via CupertinoApp or a manual CupertinoTheme widget).
-
MediaQuery.platformBrightnessOf — the device/OS system setting. Safe fallback for pure CupertinoApp with no explicit brightness pin.
The GlassThemeData.brightness explicit glass-theme override is checked by GlassTheme.brightnessOf before calling this function.
Never call this function directly from widgets. Always use GlassTheme.brightnessOf so the glass-theme override is correctly honoured.
⚠ Manual testing required
See MANUAL_TEST_CHECKLIST.md for the required pre-release device check (OS Dark Mode + ThemeMode.light → shadows must remain visible).
Implementation
Brightness resolveGlassBrightness(BuildContext context) {
// Level 1: external resolver provided by the app (e.g. Theme.maybeBrightnessOf
// from a MaterialApp integration). Zero material imports required in this file.
final externalBrightness = glassExternalBrightnessResolver?.call(context);
if (externalBrightness != null) return externalBrightness;
// Level 2: explicit CupertinoTheme pin.
final cupertinoBrightness = CupertinoTheme.of(context).brightness;
if (cupertinoBrightness != null) return cupertinoBrightness;
// Level 3: device/OS system brightness (safe fallback).
return MediaQuery.platformBrightnessOf(context);
}