getValueForScreenType<T> function Null safety

T getValueForScreenType<T>(
  1. {required BuildContext context,
  2. required T mobile,
  3. T? tablet,
  4. T? desktop,
  5. T? watch}

Will return one of the values passed in for the device it's running on


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 == && watch != null) {
    return watch;

  // If none of the layouts above are supplied or we're on the mobile layout then we show the mobile layout
  return mobile;