I'm a new Flutter developer, I'm about to develop a Flutter app which needs to use device id so I decided to use the device_info_plus
package to get androidId
, but when I request device info in order to get androidId
within it, it returns null
and also does not even exist in toMap()
object. I don't know exactly what happened but all the documentation I went through says that this package could give me the device id.
Here is the function
Future<Object?> 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;
print(androidDeviceInfo.androidId);
return androidDeviceInfo.androidId; // unique ID on Android
}
return false;
}
androidId
functionality was removed from version 4.0.0.
You can see it from the Changelog here.
If you'd like to get androidId
, you need to downgrade device_info_plus in pubspec.yaml
device_info_plus: 3.2.4
P.S. There is the issue on Github that you can upvote. Probably this functionality will be returned.