getDeviceDetails function
Implementation
Future<DeviceDetails> getDeviceDetails(BuildContext context) async {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
String device = '';
String os = Platform.operatingSystem;
if (Platform.isAndroid) {
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
device = androidInfo.model ?? '';
os += ' ${androidInfo.version.release}';
} else if (Platform.isIOS) {
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
device = iosInfo.model ?? '';
os += ' ${iosInfo.systemVersion}';
}
final screenSize = MediaQuery.of(context).size;
String screenResolution = '${screenSize.width}x${screenSize.height}';
List<ConnectivityResult> connectivityResult = await Connectivity().checkConnectivity();
String networkType = connectivityResult.toString().split('.').last;
String? batteryLevelStr;
if (Platform.isAndroid) {
Battery battery = Battery();
int batteryLevel = await battery.batteryLevel;
batteryLevelStr = '$batteryLevel%';
}
return DeviceDetails(
device: device,
os: os,
screenResolution: screenResolution,
networkType: networkType,
batteryLevel: batteryLevelStr??"",
);
}