Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - Get Android device name

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?

like image 761
Amani Elsaed Avatar asked May 02 '26 19:05

Amani Elsaed


1 Answers

This is what I implemented, only tested for android and iOS. Essentially, iOS uses name, while Android uses manufacturer and model. In most cases I believe you can replace brand for manufacturer, I didn't have a lot of test devices, do your own research.

import 'package:device_info/device_info.dart';

String getDeviceName(){
    Map deviceInfo = (await DeviceInfoPlugin().deviceInfo).data;
    String? brand = deviceInfo['brand'];
    String? model = deviceInfo['model'];
    String? name = deviceInfo['name'];

    return name ?? '$manufacturer $model';
}
like image 53
DAVID BASSEY Avatar answered May 04 '26 08:05

DAVID BASSEY



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!