deviceType method

DeviceType deviceType(
  1. BuildContext context
)

Implementation

DeviceType deviceType(BuildContext context) {
  var deviceType = DeviceType.web;
  final screenWidth = MediaQuery.of(context).size.width;
  final screenHeight = MediaQuery.of(context).size.height;
  final orientation = MediaQuery.of(context).orientation;

  if (kIsWeb) {
    deviceType = DeviceType.web;
  } else {
    bool isMobile = defaultTargetPlatform == TargetPlatform.iOS || defaultTargetPlatform == TargetPlatform.android;
    bool isTablet = (orientation == Orientation.portrait && screenWidth >= 600) || (orientation == Orientation.landscape && screenHeight >= 600);

    if (isMobile) {
      deviceType = isTablet ? DeviceType.tablet : DeviceType.mobile;
    } else {
      switch (defaultTargetPlatform) {
        case TargetPlatform.linux:
          deviceType = DeviceType.linux;
          break;
        case TargetPlatform.macOS:
          deviceType = DeviceType.mac;
          break;
        case TargetPlatform.windows:
          deviceType = DeviceType.windows;
          break;
        case TargetPlatform.fuchsia:
          deviceType = DeviceType.fuchsia;
          break;
        default:
          break;
      }
    }
  }

  return deviceType;
}