getDeviceType function

DeviceType getDeviceType()

Implementation

DeviceType getDeviceType() {
  String userAgent = html.window.navigator.userAgent.toString().toLowerCase();
  // smartphone
  if (userAgent.contains("iphone") || userAgent.contains("android")) return DeviceType.smartphone;

  // tablet
  if (userAgent.contains("ipad") ||
      (html.window.navigator.platform?.toLowerCase().contains("macintel") ?? false) && (html.window.navigator.maxTouchPoints ?? 0) > 0)
    return DeviceType.tablet;

  return DeviceType.desktop;
}