resolveAdaptiveRadius static method
Resolves an adaptive border radius based on the device's physical geometry.
This algorithm uses MediaQuery safe area insets to infer the ideal corner radius, handling Dynamic Island, Notch iPhones, and Android devices without hardcoding specific model names.
Implementation
static double resolveAdaptiveRadius(BuildContext context) {
// D2: Use scoped MediaQuery accessors instead of MediaQuery.of(context).
// MediaQuery.of() subscribes to ALL MediaQuery changes (keyboard, status bar,
// orientation, text scale, etc.) — causing every glass widget to rebuild when
// the keyboard appears/dismisses. We only need viewPadding and screen height.
final viewPadding = MediaQuery.viewPaddingOf(context);
final bottom = viewPadding.bottom;
final top = viewPadding.top;
final theme = GlassThemeData.of(context);
final themeRadius = theme.borderRadiusFor(context);
// 0. If user specified a global radius in the theme, respect it.
if (themeRadius != null) return themeRadius;
final platform = defaultTargetPlatform;
final height = MediaQuery.sizeOf(context).height;
final isIOS = platform == TargetPlatform.iOS;
// 1. Devices with physical home buttons or desktop (no bottom safe area)
if (bottom == 0) return 0.0;
if (isIOS) {
// 2. iPhone Pro Max / Plus with Dynamic Island (e.g. 15 Pro Max: height 932)
// Height is the most reliable indicator; top padding can fluctuate.
if (height >= 900) return 54.0;
// 3. iPhone Pro / Base with Dynamic Island (e.g. 15 Pro: height 852)
if (height >= 800 || top >= 54) return 46.0;
// 4. iPhone with Notch (typically top padding between 44 and 50)
return 46.0;
} else {
// 4. Android devices with gesture navigation (bottom > 0)
// Android flags often have softer, smaller curves than Apple.
return 28.0;
}
}