Flutter - Get Android device name

Viewed 9282

I am implementing an app using Flutter and I want to get the device name, i.e. X's Huawei phone, using device_info package.

I could get it in iOS using this code:

IosDeviceInfo iosDeviceInfo = await deviceInfo.iosInfo;
print('device name ${iosDeviceInfo.name}');

But in Android, I couldn't get the name. I can get many other values like the model, brand and display.

Is there a parameter in this package or another package that I can get Android device's name from it?

2 Answers

You can get Android device's name from board:

if(Platform.isAndroid){
  AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
  return androidInfo.board;
}

device_info package provides getting Android and iOS device info. It doesn't support any other platform as of now.

import 'package:device_info/device_info.dart';

DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
print('Running on ${androidInfo.model}');  // e.g. "Moto G (4)"

IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
print('Running on ${iosInfo.utsname.machine}');  // e.g. "iPod7,1"
Related