Files
hgmj_android/analytics_sdk/lib/utils/device_info_util.dart
T
2026-10-08 11:37:25 +07:00

37 lines
1.3 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'device_info_native.dart'
// ignore: uri_does_not_exist
if (dart.library.html) 'device_info_web.dart';
/// 设备信息工具类:SDK 内部自动检测,业务方无需手动传入。
///
/// 使用前须在 SDK 初始化时调用一次 [initialize],之后所有 getter 同步返回缓存值。
class DeviceInfoUtil {
static bool _initialized = false;
/// 异步初始化(调用 device_info_plus 获取品牌/型号并缓存)。
/// 重复调用无副作用。
static Future<void> initialize() async {
if (_initialized) return;
_initialized = true;
await initializeDeviceInfo();
}
/// 设备类型:Android / iOS / PC
static String get deviceType => getDeviceType();
/// 操作系统名称:Android / iOS / macOS / Windows / Linux / Web
static String get systemName => getSystemName();
/// 操作系统版本号
static String get systemVersion => getSystemVersion();
/// 设备品牌(由 device_info_plus 自动获取)
static String get deviceBrand => getDeviceBrand();
/// 设备型号(由 device_info_plus 自动获取)
static String get deviceModel => getDeviceModel();
/// User-Agent(Web 端自动读取,Native 端返回空字符串)
static String get userAgent => getUserAgent();
}