responsiveIconScale static method

double responsiveIconScale()

Computes a responsive scale factor based on the device's shortest screen dimension. Reference device: ~390pt width (iPhone 14 / standard phone) → factor 1.0.

• iPhone SE (~375pt) → ~0.88 (icons shrink ~12%) • Standard phone (~390pt) → 1.0 (baseline — no change) • Large phone (~430pt) → 1.0 (capped at 1.0) • Tablet (~768pt+) → ~0.70–0.75 (icons shrink 25-30% for larger viewport)

The result is cached after the first call since shortest side never changes regardless of device orientation.

Implementation

static double responsiveIconScale() {
  if (_cachedIconScale != null) return _cachedIconScale!;

  try {
    final view = PlatformDispatcher.instance.views.first;
    final shortest =
        view.physicalSize.shortestSide / view.devicePixelRatio;

    if (shortest >= 600) {
      // Tablet: scale down so icons don't dominate the larger map viewport
      _cachedIconScale = (390.0 / shortest).clamp(0.55, 0.80);
    } else {
      // Phone: scale relative to reference width 390pt
      _cachedIconScale = (shortest / 390.0).clamp(0.80, 1.0);
    }
  } catch (_) {
    _cachedIconScale = 1.0; // Fallback: no scaling
  }

  return _cachedIconScale!;
}