getDeviceType function

DeviceScreensType getDeviceType(
  1. BuildContext context
)

Implementation

DeviceScreensType getDeviceType(BuildContext context) {
  final MediaQueryData mediaQuery = MediaQuery.of(context);
  final Orientation deviceOrientation = mediaQuery.orientation;
  double deviceWidth = 0;
  if (deviceOrientation == Orientation.landscape) {
    deviceWidth = mediaQuery.size.height;
  } else {
    deviceWidth = mediaQuery.size.width;
  }

  if (deviceWidth > 1200) {
    return DeviceScreensType.Desktop;
  }
  if (deviceWidth > 600) {
    return DeviceScreensType.Tablet;
  }
  return DeviceScreensType.Mobile;
}