flexValueWithContext method

  1. @Deprecated('Usa .flexValue en su lugar (sin context). Será eliminado en v3.0.0')
int flexValueWithContext(
  1. BuildContext context, {
  2. int? web,
  3. int? ios,
  4. int? android,
  5. int? mobile,
  6. int? tablet,
  7. int? desktop,
})

Flex Value Responsive (DEPRECATED): Usa .flexValue en su lugar (sin context).

Esta versión con context será eliminada en futuras versiones. Migra tu código a usar .flexValue directamente sin pasar context.

Implementation

@Deprecated('Usa .flexValue en su lugar (sin context). Será eliminado en v3.0.0')
int flexValueWithContext(BuildContext context, {
  int? web,
  int? ios,
  int? android,
  int? mobile,
  int? tablet,
  int? desktop,
}) {
  final screenInfo = ScreenScalerInheritedWidget.of(context)?.info;
  if (screenInfo == null) {
    throw FlutterError('ResponsiveFlex requiere ScreenSizeInitializer');
  }

  // Si no se especifican parámetros multi-plataforma, usar comportamiento básico
  if (web == null && ios == null && android == null &&
      mobile == null && tablet == null && desktop == null) {
    // Ajuste de flex basado en el tipo de dispositivo
    switch (screenInfo.deviceType) {
      case DeviceType.mobile:
        return this; // Mantener valor original en mobile
      case DeviceType.tablet:
        return (this * 1.2).round(); // Incrementar ligeramente en tablet
      case DeviceType.desktop:
        return (this * 1.5).round(); // Incrementar más en desktop
      default:
        return this;
    }
  }

  // Usar lógica multi-plataforma con 'this' como fallback
  switch (screenInfo.deviceType) {
    case DeviceType.web:
      return web ?? desktop ?? this;
    case DeviceType.ios:
      return ios ?? mobile ?? this;
    case DeviceType.android:
      return android ?? mobile ?? this;
    case DeviceType.mobile:
      return mobile ?? this;
    case DeviceType.tablet:
      return tablet ?? this;
    case DeviceType.desktop:
      return desktop ?? web ?? this;
  }
}