spWithContext method

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

Tamaño de Fuente Responsive (DEPRECATED): Usa .sp en su lugar (sin context).

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

Implementation

@Deprecated('Usa .sp en su lugar (sin context). Será eliminado en v3.0.0')
double spWithContext(BuildContext context, {
  num? web,
  num? ios,
  num? android,
  num? mobile,
  num? tablet,
  num? desktop,
}) {
  final screenInfo = _getInfo(context);

  // 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) {
    // Para sp, usamos una base diferente dependiendo del formato
    final double baseSize;
    if (this <= 1) {
      // Si es decimal (0-1), multiplicamos directamente por el ancho
      baseSize = screenInfo.width * this;
    } else {
      // Si es porcentaje (0-100), usamos la lógica original
      baseSize = screenInfo.width * (this / 1000);
    }

    return baseSize * screenInfo.textScale;
  }

  // Usar lógica multi-plataforma con 'this' como fallback
  final values = <DeviceType, num>{};
  if (web != null) values[DeviceType.web] = web;
  if (ios != null) values[DeviceType.ios] = ios;
  if (android != null) values[DeviceType.android] = android;
  if (mobile != null) values[DeviceType.mobile] = mobile;
  if (tablet != null) values[DeviceType.tablet] = tablet;
  if (desktop != null) values[DeviceType.desktop] = desktop;

  final rawValue = _getValueForDevice(screenInfo, values, this);

  // Aplicar la misma lógica de escalado que en el modo básico
  final double baseSize;
  if (rawValue <= 1) {
    // Si es decimal (0-1), multiplicamos directamente por el ancho
    baseSize = screenInfo.width * rawValue;
  } else {
    // Si es valor tradicional, usamos la lógica original
    baseSize = screenInfo.width * (rawValue / 1000);
  }

  return baseSize * screenInfo.textScale;
}