responsiveValue<T> method
T
responsiveValue<T>({
- T? watch,
- T? mobile,
- T? tablet,
- T? desktop,
Returns a specific value according to the screen size
if the device width is higher than or equal to 1200 return
desktop value. if the device width is higher than or equal to 600
and less than 1200 return tablet value.
if the device width is less than 300 return watch value.
in other cases return mobile value.
Implementation
T responsiveValue<T>({T? watch, T? mobile, T? tablet, T? desktop}) {
assert(
watch != null || mobile != null || tablet != null || desktop != null,
);
final deviceWidth = mediaQuerySize.width;
if (deviceWidth >= 1200 && desktop != null) return desktop;
if (deviceWidth >= 600 && tablet != null) return tablet;
if (deviceWidth >= 300 && mobile != null) return mobile;
if (watch != null) return watch;
return desktop ?? tablet ?? mobile ?? watch!;
}