How to get unique device id in flutter?
flutter, flutter-dependencies
Solution
Null safe code
Use device_info_plus plugin developed by Flutter community. This is how you can get IDs on both platform.
In your `pubspec.yaml` file add this:
dependencies:
device_info_plus: ^3.2.3
Create a method:
Future<String?> _getId() async {
var deviceInfo = DeviceInfoPlugin();
if (Platform.isIOS) { // import 'dart:io'
var iosDeviceInfo = await deviceInfo.iosInfo;
return iosDeviceInfo.identifierForVendor; // unique ID on iOS
} else if(Platform.isAndroid) {
var androidDeviceInfo = await deviceInfo.androidInfo;
return androidDeviceInfo.androidId; // unique ID on Android
}
}
Usage:
String? deviceId = await _getId();
Problem
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?