Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get unique device id in flutter?

In Android we have, Settings.Secure.ANDROID_ID. I do not know the iOS equivalent. Is there a flutter plugin or a way to get a unique device id for both Android and IOS in flutter?

like image 840
karan vs Avatar asked Jul 11 '17 10:07

karan vs


People also ask

How do I find the unique ID in Flutter?

If you need only the id of the device that your app is running on, the simplest and quickest solution is to use the platform_device_id package. It works on Android (AndroidId), iOS (IdentifierForVendor), Windows (BIOS UUID), macOS (IOPlatformUUID), and Linux (BIOS UUID).

How do I get device info on Flutter?

We can get current device information from within the Flutter application by using the device_info_plus package. Which is supports all kinds of platforms, including Android, iOS, macOS, web, Linux, and Windows.


1 Answers

There is a plugin called device_info. You can get it here.

Check the official example here

 static Future<List<String>> getDeviceDetails() async {     String deviceName;     String deviceVersion;     String identifier;     final DeviceInfoPlugin deviceInfoPlugin = new DeviceInfoPlugin();     try {       if (Platform.isAndroid) {         var build = await deviceInfoPlugin.androidInfo;         deviceName = build.model;         deviceVersion = build.version.toString();         identifier = build.androidId;  //UUID for Android       } else if (Platform.isIOS) {         var data = await deviceInfoPlugin.iosInfo;         deviceName = data.name;         deviceVersion = data.systemVersion;         identifier = data.identifierForVendor;  //UUID for iOS       }     } on PlatformException {       print('Failed to get platform version');     }  //if (!mounted) return; return [deviceName, deviceVersion, identifier]; } 

You can store this UUID in the Keychain. This way you can set an unique ID for your device.

like image 64
Chaythanya Nair Avatar answered Oct 13 '22 05:10

Chaythanya Nair