resolveAdaptiveRadius static method

double resolveAdaptiveRadius(
  1. BuildContext context
)

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 16/17/18 Pro (height 874) and Pro Max / Plus (height >= 900)
    // have 62pt display bezel corners → 54pt concentric sheet bottom radius.
    if (height >= 870) return 54.0;

    // 3. iPhone 14/15 Pro / Base with Dynamic Island (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;
  }
}