getDeviceInfo static method
Retrieves comprehensive device information for web platforms
Returns a map containing device details including:
- Device name and browser information
- Operating system and version
- Processor information (architecture, core count)
- Memory information
- Display specifications (resolution, pixel density)
- Security information
Throws DeviceInfoException if device information cannot be retrieved.
Implementation
static Future<Map<String, dynamic>> getDeviceInfo() async {
try {
final window = web.window;
final screen = window.screen;
final navigator = window.navigator;
// Get user agent info
final userAgent = navigator.userAgent;
// Get screen info
final screenWidth = screen.width.toInt();
final screenHeight = screen.height.toInt();
final pixelRatio = window.devicePixelRatio;
// Get hardware concurrency (CPU cores)
final hardwareConcurrency = navigator.hardwareConcurrency;
// Get memory info (if available)
final memory = _getMemoryInfo();
// Detect browser
final browserInfo = _detectBrowser(userAgent);
return {
'deviceName': browserInfo['name'] ?? 'Web Browser',
'manufacturer': 'Unknown',
'model': browserInfo['name'] ?? 'Web Browser',
'brand': browserInfo['name'] ?? 'Web',
'operatingSystem': _detectOS(userAgent),
'systemVersion': _getOSVersion(userAgent),
'buildNumber': 'Unknown',
'kernelVersion': 'Web Engine',
'processorInfo': {
'architecture': _detectArchitecture(userAgent),
'coreCount': hardwareConcurrency,
'maxFrequency': 0,
'processorName': 'JavaScript Engine',
'features': _getProcessorFeatures(),
},
'memoryInfo': memory,
'displayInfo': {
'screenWidth': screenWidth,
'screenHeight': screenHeight,
'pixelDensity': pixelRatio,
'refreshRate': _getRefreshRate(),
'screenSizeInches': _calculateScreenSize(
screenWidth,
screenHeight,
pixelRatio,
),
'orientation': screenWidth > screenHeight ? 'landscape' : 'portrait',
'isHdr': _checkHdrSupport(),
},
'securityInfo': {
'isDeviceSecure': false,
'hasFingerprint': false,
'hasFaceUnlock': false,
'screenLockEnabled': false,
'encryptionStatus': window.location.protocol == 'https:'
? 'encrypted'
: 'unencrypted',
},
};
} catch (e) {
throw DeviceInfoException('Failed to get device info: $e');
}
}