Detect whether the device is phone, tablet or tv on flutter

Viewed 1694

I want to know whether the used device is tv or not..I am using flutter_device_type package but it only detects the tablet and consider any other device as phone

2 Answers

By default flutter detects the device based on its minimum size(screens bigger than a minimum width considered as a tablet), something like this code:

  String getDeviceType() {
    final data = MediaQueryData.fromWindow(WidgetsBinding.instance.window);
    return data.size.shortestSide < 600 ? 'phone' :'tablet';
  }

In another hand with Java/Kotlin and based on this documentation you can detect if the device is android Tv with this code:

val uiModeManager = getSystemService(UI_MODE_SERVICE) as UiModeManager
if (uiModeManager.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION) {
    Log.d(TAG, "Running on a TV Device")
} else {
    Log.d(TAG, "Running on a non-TV Device")
}

So the proper option would be using a native code and connecting it to flutter using platform-channels

Related