Flutter - Get Unique Device Id
I am making an app with token based system. So users can buy tokens and using them they can make some actions. Each user gets 10 tokens for free (as a trial version) after creating
Solution 1:
Use device_info_plus plugin.
In your pubspec.yaml
file add this
dependencies:device_info_plus:any
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 {
var androidDeviceInfo = await deviceInfo.androidInfo;
return androidDeviceInfo.androidId; // Unique ID on Android
}
}
Use it like:
String? deviceId = await_getId();
or
_getId().then((id) {
String? deviceId = id;
});
Solution 2:
Yes thats the plugin you need. If you really want to
I want to prevent that user gets another 10 tokens by getting a new account each time
You must as well check for rooted phone (it can change id)
You may want to consider using this GET IMEI
Post a Comment for "Flutter - Get Unique Device Id"