Browse Source
添加 device_marketing_names 依赖,用于获取设备市售名称 创建 device_info_helper 模块统一读取设备品牌、型号、操作系统信息 扩展 buildCommentUrl 函数,支持传入设备信息参数,便于后台按设备维度筛选newdev_shunjiawei
4 changed files with 85 additions and 2 deletions
@ -0,0 +1,61 @@ |
|||||
|
import 'dart:io' show Platform; |
||||
|
|
||||
|
import 'package:device_info_plus/device_info_plus.dart'; |
||||
|
import 'package:device_marketing_names/device_marketing_names.dart'; |
||||
|
|
||||
|
import '../../core/utils/logger.dart'; |
||||
|
|
||||
|
/// 反馈系统上报到评论后台的设备信息。 |
||||
|
class CommentDeviceInfo { |
||||
|
final String? brand; |
||||
|
final String? model; |
||||
|
final String? osType; |
||||
|
final String? osVersion; |
||||
|
|
||||
|
const CommentDeviceInfo({ |
||||
|
this.brand, |
||||
|
this.model, |
||||
|
this.osType, |
||||
|
this.osVersion, |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/// 读取设备信息:`model` 优先取 `device_marketing_names` 的市售名, |
||||
|
/// 命中失败时退化为 "品牌 + 内部型号",不影响功能。 |
||||
|
Future<CommentDeviceInfo> readCommentDeviceInfo() async { |
||||
|
try { |
||||
|
final plugin = DeviceInfoPlugin(); |
||||
|
final marketingNames = DeviceMarketingNames(); |
||||
|
|
||||
|
if (Platform.isIOS) { |
||||
|
final info = await plugin.iosInfo; |
||||
|
final code = info.utsname.machine; |
||||
|
final marketing = await marketingNames.getSingleName(); |
||||
|
return CommentDeviceInfo( |
||||
|
brand: 'Apple', |
||||
|
model: marketing.isNotEmpty ? marketing : code, |
||||
|
osType: 'ios', |
||||
|
osVersion: info.systemVersion, |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
if (Platform.isAndroid) { |
||||
|
final info = await plugin.androidInfo; |
||||
|
final brand = _capitalize(info.brand); |
||||
|
final marketing = await marketingNames.getSingleName(); |
||||
|
final fallback = '$brand ${info.model}'; |
||||
|
return CommentDeviceInfo( |
||||
|
brand: brand, |
||||
|
model: marketing.isNotEmpty ? marketing : fallback, |
||||
|
osType: 'android', |
||||
|
osVersion: info.version.release, |
||||
|
); |
||||
|
} |
||||
|
} catch (e) { |
||||
|
Logger.error('读取设备信息失败: $e'); |
||||
|
} |
||||
|
return const CommentDeviceInfo(); |
||||
|
} |
||||
|
|
||||
|
String _capitalize(String s) => |
||||
|
s.isEmpty ? s : s[0].toUpperCase() + s.substring(1).toLowerCase(); |
||||
Loading…
Reference in new issue