getDeviceType static method

DeviceScreenType getDeviceType(
  1. MediaQueryData mediaQuery
)

Returns the device screen type based on the mediaQuery.

Devices are assumed to be tablets if their width (in portrait) or height (in landscape) is greater than a predefined number (600)

Implementation

static DeviceScreenType getDeviceType(MediaQueryData mediaQuery) {
  final orientation = mediaQuery.orientation;
  var deviceWidth = 0.0;
  if (orientation == Orientation.landscape) {
    deviceWidth = mediaQuery.size.height;
  } else {
    deviceWidth = mediaQuery.size.width;
  }
  if (deviceWidth > 600) {
    return DeviceScreenType.Tablet;
  }
  return DeviceScreenType.Mobile;
}