device_info_handler.dart
1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import 'dart:io';
import 'package:appframe/services/dispatcher.dart';
import 'package:device_info_plus/device_info_plus.dart';
class DeviceInfoHandler extends MessageHandler {
@override
Future<Map<String, dynamic>> handleMessage(dynamic params) async {
var deviceInfoPlugin = DeviceInfoPlugin();
// 测试效果,先随便响应一些数据
if (Platform.isAndroid) {
AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo;
return {
'abi': '${androidInfo.supportedAbis}',
'deviceAbi': androidInfo.supportedAbis.isNotEmpty ? androidInfo.supportedAbis[0] : '',
'benchmarkLevel': -1,
'brand': androidInfo.brand,
'model': androidInfo.model,
'system': androidInfo.version.release,
'platform': "Android",
'cpuType': androidInfo.hardware,
"memorySize": androidInfo.physicalRamSize,
};
} else if (Platform.isIOS) {
IosDeviceInfo iosInfo = await deviceInfoPlugin.iosInfo;
return {
"brand": "Apple",
"model": iosInfo.model,
"system": iosInfo.systemVersion,
"platform": "iOS",
"memorySize": (iosInfo.physicalRamSize ~/ (1024 * 1024)).toString(),
};
} else {
return {};
}
}
}