You can use @Rohan's answer also. platform_device_id
package. Read more
There is guide for device_info_plus
package Read more
add package to your flutter project.
Create a method like this:
Future<String> getUniqueDeviceId() async {
String uniqueDeviceId = '';
var deviceInfo = DeviceInfoPlugin();
if (Platform.isIOS) {
var iosDeviceInfo = await deviceInfo.iosInfo;
uniqueDeviceId =
'${iosDeviceInfo.name}:${iosDeviceInfo.identifierForVendor}'; //
unique ID on iOS
} else if(Platform.isAndroid) {
var androidDeviceInfo = await deviceInfo.androidInfo;
uniqueDeviceId =
'${androidDeviceInfo.name}:${androidDeviceInfo.id}' ; // unique ID
on Android
}
return uniqueDeviceId;
}
use it like this:
String deviceId = await getUniqueDeviceId();
Note (updateded):
Don't use androidDeviceInfo.androidId
. This would change when your mac address changes. Mobile devices above Android OS 10/11
will generate a randomized MAC. This feature is enabled by default unless disabled manually. This would cause the androidId
to change when switiching networks. You can confirm this by yourself by changing androidDeviceInfo.id
to androidDeviceInfo.androidId
above.
(Got details from @Ariel)