value<T> static method
T
value<T>({
- T? mobileSmall,
- T? mobile,
- T? tabletSmall,
- T? tablet,
- T? desktop,
- T? desktopLarge,
Picks the value for the current DeviceType, falling back in this order
when the preferred value is null: desktopLarge → desktop → tablet → tabletSmall → mobile → mobileSmall.
Provide at least one non-null argument; otherwise an assertion will fire in debug mode. This mirrors the fallback logic used by Responsive.
Implementation
static T value<T>({
T? mobileSmall,
T? mobile,
T? tabletSmall,
T? tablet,
T? desktop,
T? desktopLarge,
}) {
assert(
mobileSmall != null ||
mobile != null ||
tabletSmall != null ||
tablet != null ||
desktop != null ||
desktopLarge != null,
'Provide at least one value to ResponsiveUtils.value.',
);
switch (currentDeviceType) {
case DeviceType.desktopLarge:
return desktopLarge ??
desktop ??
tablet ??
tabletSmall ??
mobile ??
mobileSmall as T;
case DeviceType.desktop:
return desktop ??
tablet ??
tabletSmall ??
mobile ??
mobileSmall as T;
case DeviceType.tablet:
return tablet ??
tabletSmall ??
mobile ??
mobileSmall as T;
case DeviceType.tabletSmall:
return tabletSmall ??
mobile ??
mobileSmall as T;
case DeviceType.mobile:
return mobile ??
mobileSmall as T;
case DeviceType.mobileSmall:
return mobileSmall ??
mobile as T;
default:
return mobileSmall ??
mobile ??
tabletSmall ??
tablet ??
desktop ??
desktopLarge as T;
}
}