_setPlatformType() {
if (Platform.isAndroid) {
setState(() {
type = 'Android';
});
} else if (Platform.isIOS) {
setState(() {
type = 'iOS';
});
} else {
setState(() {
type = 'other';
});
}
}
void checkPermissionAndAccessIMEI() async {
PermissionStatus status = await Permission.phone.status;
if (!status.isGranted) {
status = await Permission.phone.request();
if (!status.isGranted) {
// Handle the case when the permission is denied by the user
AppUtils.showErrorSnackBar("Give permission to access app");
return;
}
}
// The permission has been granted, you can now access the IMEI
// Your code to access the IMEI goes here
_getImei();
// Platform messages are asynchronous, so we initialize in an async method.
Future initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion = await _deviceImeiPlugin.getPlatformVersion() ??
'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
Here is my code and also I have given permission in manifest file
@override void initState() { super.initState(); // if (PreferenceManagerUtils.getIsImeiNumber() == "") { initPlatformState(); _setPlatformType(); checkPermissionAndAccessIMEI(); // } }
_setPlatformType() { if (Platform.isAndroid) { setState(() { type = 'Android'; }); } else if (Platform.isIOS) { setState(() { type = 'iOS'; }); } else { setState(() { type = 'other'; }); } }
void checkPermissionAndAccessIMEI() async { PermissionStatus status = await Permission.phone.status;
}
_getImei() async { PermissionStatus permission = await Permission.phone.status; printData("device imei 0", deviceImei??"Not found");
}
// Platform messages are asynchronous, so we initialize in an async method. Future initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion = await _deviceImeiPlugin.getPlatformVersion() ??
'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
}
Here is my code and also I have given permission in manifest file