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


Solution 1: Payam Asefi

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


Solution 2: mtkopone

You can use the device_info_plus package for detecting Android TV.

The AndroidDeviceInfo class contains a list of all the system's features as documented in the Android PackageManager

For detecting TV, you can use e.g:

DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
bool isTV = androidInfo.systemFeatures.contains('android.software.leanback_only')