resolveSettings static method
LiquidGlassSettings
resolveSettings(
- BuildContext context, {
- LiquidGlassSettings? explicit,
- LiquidGlassSettings fallback = const LiquidGlassSettings(),
- bool isOverlayPlatter = false,
Resolves LiquidGlassSettings for a widget using the full priority chain.
This is the theme-aware counterpart to InheritedLiquidGlass.ofOrDefault.
Unlike that method, it adds a final GlassThemeData fallback so that
standalone widgets (not wrapped in AdaptiveLiquidGlassLayer) still
receive a visible glassColor on light and dark backgrounds.
Priority chain (highest → lowest):
explicit— the widget's ownsettings:parameter (non-null wins).- InheritedLiquidGlass — settings from nearest parent layer.
- LiquidGlassWidgets.globalSettings — app-level global override.
- GlassThemeData — brightness-aware theme settings (light/dark).
- LiquidGlassSettings default — absolute last resort.
Call sites in GlassButton, GlassContainer, and GlassTextField use
this instead of InheritedLiquidGlass.ofOrDefault() so that a standalone
GlassButton(useOwnLayer: true) is never invisible on a white background.
Implementation
static LiquidGlassSettings resolveSettings(
BuildContext context, {
LiquidGlassSettings? explicit,
LiquidGlassSettings fallback = const LiquidGlassSettings(),
bool isOverlayPlatter = false,
}) {
// 1. Widget-level explicit setting wins unconditionally.
if (explicit != null) return explicit;
// 2. Inherited settings from the nearest AdaptiveLiquidGlassLayer.
// When the ancestor layer had no explicit `settings:` of its own and
// only synthesized default theme settings, let widgets with a dedicated
// per-widget fallback (e.g. GlassMenu, GlassSheet) resolve via Step 4
// so their per-widget classic optics are preserved inside GlassScaffold.
final inherited = InheritedLiquidGlass.of(context);
if (inherited != null &&
(InheritedLiquidGlass.hasExplicitSettingsOf(context) ||
(fallback == const LiquidGlassSettings() && !isOverlayPlatter))) {
return inherited;
}
// 3. App-level global override (set via LiquidGlassWidgets.globalSettings).
if (LiquidGlassWidgets.globalSettings != null) {
return LiquidGlassWidgets.globalSettings!;
}
// 4. Theme fallback — ensures glass is visible even when no settings are
// provided anywhere. Mirrors the logic in AdaptiveLiquidGlassLayer:
// start from the zero-alpha default, then overlay any non-null fields
// from the theme's brightness-appropriate variant.
// When [GlassStyle.classic] is active and the caller supplies a
// dedicated widget fallback (e.g. [kDefaultSheetSettings] or
// `kDefaultMenuSettings`), apply only custom theme deltas from the
// classic surface baseline so widget-specific classic optics (such as
// sheet `refractiveIndex: 0.15`) are preserved.
final themeData = GlassThemeData.of(context);
final themeOverride = themeData.settingsFor(context);
if (themeOverride == null) return fallback;
final isDark = GlassTheme.brightnessOf(context) == Brightness.dark;
if (themeData.style == GlassStyle.classic &&
fallback != const LiquidGlassSettings()) {
final classicBaseline = isDark
? GlassThemeSettings.classicDark
: GlassThemeSettings.classicLight;
return themeOverride.applyDeltaTo(fallback, classicBaseline);
}
final resolved = themeOverride.applyTo(fallback);
if (isOverlayPlatter &&
themeData.style != GlassStyle.classic &&
resolved.frost > 0) {
final surfaceBaseline = themeData.style == GlassStyle.ios27
? (isDark
? GlassThemeSettings.ios27Dark
: GlassThemeSettings.ios27Light)
: (isDark
? GlassThemeSettings.ios26Dark
: GlassThemeSettings.ios26Light);
// Native iOS 26 / iOS 27 floating overlay platters (_UIContextMenuPlatterView
// and _UISheetPresentationController) use the full 14pt frosted cloud
// (`frostOpacity: 1.0`) so sharp background text does not ghost through
// behind dense menu or sheet text. Preserve any custom frostOpacity set
// by the user on the active GlassThemeVariant.
if (themeOverride.frostOpacity == surfaceBaseline.frostOpacity) {
return resolved.copyWith(frostOpacity: 1.0);
}
}
return resolved;
}