Skip to content

Instantly share code, notes, and snippets.

@encikpulasan
Created June 25, 2021 05:57
Show Gist options
  • Save encikpulasan/281ea98ad14cab49ccf498d8da416407 to your computer and use it in GitHub Desktop.
Save encikpulasan/281ea98ad14cab49ccf498d8da416407 to your computer and use it in GitHub Desktop.
Flutter Device Info Utility Helper
import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart';
class DeviceInfoUtils {
final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
/// Info available for both iOS & Android OS
String? deviceId;
String? deviceName;
String? deviceModel;
String? systemName;
String? systemVersion;
String? localizedModel;
bool? isPhysicalDevice;
/// Info only available for Android OS
String? boardName;
String? bootloaderVersion;
String? deviceBrand;
String? deviceBuildId;
String? deviceBuildFingerprint;
String? hardwareName;
String? hostName;
String? labelId;
String? manufacturerName;
String? buildTags;
String? buildType;
List<String?>? supported32BitAbis;
List<String?>? supported64BitAbis;
List<String?>? supportedAbis;
List<String?>? systemFeatures;
/// initialize to set device info value
Future<void> init() async {
if (Platform.isIOS) {
final IosDeviceInfo iosDeviceInfo = await deviceInfo.iosInfo;
this.deviceId = iosDeviceInfo.identifierForVendor;
this.deviceName = iosDeviceInfo.name;
this.deviceModel = iosDeviceInfo.model;
this.systemName = iosDeviceInfo.systemName;
this.systemVersion = iosDeviceInfo.systemVersion;
this.localizedModel = iosDeviceInfo.localizedModel;
this.isPhysicalDevice = iosDeviceInfo.isPhysicalDevice;
}
if (Platform.isAndroid) {
final AndroidDeviceInfo androidDeviceInfo = await deviceInfo.androidInfo;
this.deviceId = androidDeviceInfo.androidId;
this.deviceName = androidDeviceInfo.model;
this.deviceModel = androidDeviceInfo.device;
if (androidDeviceInfo.version.baseOS == null || androidDeviceInfo.version.baseOS == "")
this.systemName = "Android";
else
this.systemName = androidDeviceInfo.version.baseOS;
this.systemVersion = androidDeviceInfo.version.release;
this.localizedModel = androidDeviceInfo.product;
this.isPhysicalDevice = androidDeviceInfo.isPhysicalDevice;
this.boardName = androidDeviceInfo.board;
this.bootloaderVersion = androidDeviceInfo.bootloader;
this.deviceBrand = androidDeviceInfo.brand;
this.deviceBuildId = androidDeviceInfo.display;
this.deviceBuildFingerprint = androidDeviceInfo.fingerprint;
this.hardwareName = androidDeviceInfo.hardware;
this.hostName = androidDeviceInfo.host;
this.labelId = androidDeviceInfo.id;
this.manufacturerName = androidDeviceInfo.manufacturer;
this.buildTags = androidDeviceInfo.tags;
this.buildType = androidDeviceInfo.type;
this.supported32BitAbis = androidDeviceInfo.supported32BitAbis;
this.supported64BitAbis = androidDeviceInfo.supported64BitAbis;
this.supportedAbis = androidDeviceInfo.supportedAbis;
this.systemFeatures = androidDeviceInfo.systemFeatures;
}
}
void dump() {
print("""
deviceId: $deviceId
deviceName: $deviceName
deviceModel: $deviceModel
systemName: $systemName
systemVersion: $systemVersion
localizedModel: $localizedModel
isPhysicalDevice: $isPhysicalDevice
bootloaderVersion: $bootloaderVersion
deviceBuildId: $deviceBuildId
deviceBuildFingerprint: $deviceBuildFingerprint
hardwareName: $hardwareName
hostName: $hostName
labelId: $labelId
manufacturerName: $manufacturerName
buildTags: $buildTags
buildType: $buildType
supported32BitAbis: $supported32BitAbis
supported64BitAbis: $supported64BitAbis
supportedAbis: $supportedAbis
systemFeatures: $systemFeatures
""");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment