getDeviceInfo static method
Implementation
static Future<NUIDeviceInfo?> getDeviceInfo() async {
Map<String, dynamic> deviceData;
NUIDeviceInfo? deviceInfo;
loadIPAddress(); // Load ip address separately
String ip = ipAddress ?? "";
try {
if(kIsWeb){
final webBrowserInfo = await deviceInfoPlugin.webBrowserInfo;
deviceData = _readWebBrowserInfo(webBrowserInfo);
deviceInfo = NUIDeviceInfo(
model: webBrowserInfo.appCodeName,
version: webBrowserInfo.appVersion,
brand: webBrowserInfo.appName,
manufacturer: webBrowserInfo.browserName.name,
details: deviceData,
platform: NUIPlatform.WEB.value(),
ipAddress: ip
);
}else{
if (Platform.isAndroid) {
final androidDeviceInfo = await deviceInfoPlugin.androidInfo;
var uuid = md5.convert(utf8.encode(androidDeviceInfo.fingerprint)).toString();
if(uuid == "unknown" || uuid.isNullOrEmpty()){
uuid = md5.convert(utf8.encode(androidDeviceInfo.model + androidDeviceInfo.id)).toString();
}
deviceData = _readAndroidBuildData(androidDeviceInfo);
deviceInfo = NUIDeviceInfo(
uuid: uuid,
model: androidDeviceInfo.model,
version: androidDeviceInfo.version.sdkInt.toString(),
brand: androidDeviceInfo.brand,
manufacturer: androidDeviceInfo.manufacturer,
details: deviceData,
platform: NUIPlatform.ANDROID.value(),
ipAddress: ip
);
} else if (Platform.isIOS) {
final iosDeviceInfo = await deviceInfoPlugin.iosInfo;
final moreDetail = iosDeviceInfo.utsname;
final machine = moreDetail.machine;
final maskedModelName = machine.iOSProductName ?? machine ?? iosDeviceInfo.model;
final uuid = iosDeviceInfo.identifierForVendor;
deviceData = _readIosDeviceInfo(iosDeviceInfo);
deviceInfo = NUIDeviceInfo(
uuid: uuid,
model: maskedModelName,
version: iosDeviceInfo.systemVersion,
brand: "iOS",
manufacturer: "Apple",
details: deviceData,
platform: NUIPlatform.IOS.value(),
ipAddress: ip
);
}
}
} on PlatformException {
deviceData = <String, dynamic>{
'Error:': 'Failed to get platform version.'
};
deviceInfo = null;
}
return deviceInfo;
}