rw function
Ancho Responsive con variaciones por plataforma: Calcula el ancho como porcentaje de pantalla con valores específicos por dispositivo.
Ejemplos:
Container(
width: rw(mobile: 90, tablet: 70, desktop: 50),
child: ...,
)
// Con plataformas específicas
width: rw(ios: 95, android: 90, tablet: 70, web: 50)
Implementation
double rw({
num? mobile,
num? tablet,
num? desktop,
num? ios,
num? android,
num? web,
}) {
final screenInfo = ScreenInfoManager().info;
final values = <DeviceType, num>{};
if (mobile != null) values[DeviceType.mobile] = mobile;
if (tablet != null) values[DeviceType.tablet] = tablet;
if (desktop != null) values[DeviceType.desktop] = desktop;
if (ios != null) values[DeviceType.ios] = ios;
if (android != null) values[DeviceType.android] = android;
if (web != null) values[DeviceType.web] = web;
if (values.isEmpty) {
throw FlutterError('rw() requiere al menos un valor de plataforma');
}
final normalizedValue = _getValueForDevice(screenInfo, values);
return screenInfo.width * normalizedValue;
}