getValueForScreenType<T> function
T
getValueForScreenType<T>({
- required BuildContext context,
- required T mobile,
- T? tablet,
- T? desktop,
- T? watch,
Will return one of the values passed in for the device it's running on
Implementation
T getValueForScreenType<T>({
required BuildContext context,
required T mobile,
T? tablet,
T? desktop,
T? watch,
}) {
var deviceScreenType = getDeviceType(MediaQuery.of(context).size);
// If we're at desktop size
if (deviceScreenType == DeviceScreenType.desktop) {
// If we have supplied the desktop layout then display that
if (desktop != null) return desktop;
// If no desktop layout is supplied we want to check if we have the size below it and display that
if (tablet != null) return tablet;
}
if (deviceScreenType == DeviceScreenType.tablet) {
if (tablet != null) return tablet;
}
if (deviceScreenType == DeviceScreenType.watch && watch != null) {
return watch;
}
if (deviceScreenType == DeviceScreenType.mobile) {
if (mobile != null) return mobile;
}
// If none of the layouts above are supplied we use the prefered layout based on the flag
final buildDesktopLayout = ResponsiveAppUtil.preferDesktop && desktop != null;
return buildDesktopLayout ? desktop : mobile;
}