feat: add device_info_plus
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class DeviceInfoUtil {
|
||||
static final DeviceInfoPlugin _deviceInfo = DeviceInfoPlugin();
|
||||
|
||||
/// 获取设备信息
|
||||
static Future<void> printDeviceInfo() async {
|
||||
try {
|
||||
if (defaultTargetPlatform == TargetPlatform.android) {
|
||||
await _printAndroidDeviceInfo();
|
||||
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
|
||||
await _printIosDeviceInfo();
|
||||
} else {
|
||||
debugPrint('当前平台不支持: $defaultTargetPlatform');
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('获取设备信息失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// 获取 Android 设备信息
|
||||
static Future<void> _printAndroidDeviceInfo() async {
|
||||
final androidInfo = await _deviceInfo.androidInfo;
|
||||
|
||||
debugPrint('========== Android 设备信息 ==========');
|
||||
debugPrint('品牌: ${androidInfo.brand}');
|
||||
debugPrint('制造商: ${androidInfo.manufacturer}');
|
||||
debugPrint('机型: ${androidInfo.model}');
|
||||
debugPrint('设备名称: ${androidInfo.device}');
|
||||
debugPrint('产品名: ${androidInfo.product}');
|
||||
debugPrint('硬件名: ${androidInfo.hardware}');
|
||||
debugPrint('主板: ${androidInfo.board}');
|
||||
debugPrint('序列号: ${androidInfo.serialNumber}');
|
||||
debugPrint('Android ID: ${androidInfo.id}');
|
||||
debugPrint('系统版本: ${androidInfo.version.release}');
|
||||
debugPrint('SDK 版本: ${androidInfo.version.sdkInt}');
|
||||
debugPrint('安全补丁: ${androidInfo.version.securityPatch}');
|
||||
debugPrint('API 级别: ${androidInfo.version.codename}');
|
||||
debugPrint('设备类型: ${androidInfo.isPhysicalDevice ? "物理设备" : "模拟器"}');
|
||||
debugPrint('=====================================');
|
||||
}
|
||||
|
||||
/// 获取 iOS 设备信息
|
||||
static Future<void> _printIosDeviceInfo() async {
|
||||
final iosInfo = await _deviceInfo.iosInfo;
|
||||
|
||||
debugPrint('========== iOS 设备信息 ==========');
|
||||
debugPrint('设备名称: ${iosInfo.name}');
|
||||
debugPrint('系统名称: ${iosInfo.systemName}');
|
||||
debugPrint('系统版本: ${iosInfo.systemVersion}');
|
||||
debugPrint('机型: ${iosInfo.model}');
|
||||
debugPrint('本地化机型: ${iosInfo.localizedModel}');
|
||||
debugPrint('标识符: ${iosInfo.identifierForVendor}');
|
||||
debugPrint('是否是物理设备: ${iosInfo.isPhysicalDevice ? "是" : "否"}');
|
||||
debugPrint('=================================');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user