device_info_handler.dart
1.07 KB
import 'dart:io';
import 'package:appframe/services/dispatcher.dart';
import 'package:device_info_plus/device_info_plus.dart';
class DeviceInfoHandler implements MessageHandler {
@override
Future<Map<String, dynamic>> handleMessage(Map<String, dynamic> params) async {
var deviceInfoPlugin = DeviceInfoPlugin();
// 测试效果,先随便响应一些数据
if (Platform.isAndroid) {
AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo;
return {
"brand": androidInfo.brand,
"model": androidInfo.model,
"system": androidInfo.version.release,
"platform": "Android",
"memorySize": (androidInfo.physicalRamSize ~/ (1024 * 1024)).toString(),
};
} 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 {};
}
}
}