1. 升级依赖版本
2. 解决运行项目警告日志问题 3. 优化代码
This commit is contained in:
78
lib/core/platform/app_platform_info.dart
Normal file
78
lib/core/platform/app_platform_info.dart
Normal file
@@ -0,0 +1,78 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class AppPackageInfo {
|
||||
const AppPackageInfo({
|
||||
required this.appName,
|
||||
required this.packageName,
|
||||
required this.version,
|
||||
required this.buildNumber,
|
||||
});
|
||||
|
||||
factory AppPackageInfo.fromMap(Map<Object?, Object?> map) {
|
||||
return AppPackageInfo(
|
||||
appName: map['appName'] as String? ?? '',
|
||||
packageName: map['packageName'] as String? ?? '',
|
||||
version: map['version'] as String? ?? '',
|
||||
buildNumber: map['buildNumber'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
final String appName;
|
||||
final String packageName;
|
||||
final String version;
|
||||
final String buildNumber;
|
||||
}
|
||||
|
||||
class AppDeviceInfo {
|
||||
const AppDeviceInfo({
|
||||
required this.platform,
|
||||
required this.isPhysicalDevice,
|
||||
required this.values,
|
||||
});
|
||||
|
||||
factory AppDeviceInfo.fromMap(Map<Object?, Object?> map) {
|
||||
final values = <String, String>{};
|
||||
for (final entry in map.entries) {
|
||||
final key = entry.key;
|
||||
final value = entry.value;
|
||||
if (key is String && value != null) {
|
||||
values[key] = value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
final isPhysicalDevice = map['isPhysicalDevice'];
|
||||
return AppDeviceInfo(
|
||||
platform: map['platform'] as String? ?? Platform.operatingSystem,
|
||||
isPhysicalDevice: isPhysicalDevice is bool ? isPhysicalDevice : true,
|
||||
values: values,
|
||||
);
|
||||
}
|
||||
|
||||
final String platform;
|
||||
final bool isPhysicalDevice;
|
||||
final Map<String, String> values;
|
||||
}
|
||||
|
||||
class AppPlatformInfo {
|
||||
AppPlatformInfo._();
|
||||
|
||||
static const MethodChannel _channel = MethodChannel(
|
||||
'com.gdfw.fxjk/platform_info',
|
||||
);
|
||||
|
||||
static Future<AppPackageInfo> packageInfo() async {
|
||||
final result = await _channel.invokeMapMethod<Object?, Object?>(
|
||||
'packageInfo',
|
||||
);
|
||||
return AppPackageInfo.fromMap(result ?? const <Object?, Object?>{});
|
||||
}
|
||||
|
||||
static Future<AppDeviceInfo> deviceInfo() async {
|
||||
final result = await _channel.invokeMapMethod<Object?, Object?>(
|
||||
'deviceInfo',
|
||||
);
|
||||
return AppDeviceInfo.fromMap(result ?? const <Object?, Object?>{});
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:recording_tool/core/platform/app_platform_info.dart';
|
||||
|
||||
class DeviceUtils {
|
||||
DeviceUtils._();
|
||||
@@ -19,36 +19,13 @@ class DeviceUtils {
|
||||
MediaQuery.paddingOf(context).bottom;
|
||||
|
||||
static Future<bool> isPhysicalDevice() async {
|
||||
final plugin = DeviceInfoPlugin();
|
||||
if (Platform.isAndroid) {
|
||||
return (await plugin.androidInfo).isPhysicalDevice;
|
||||
}
|
||||
if (Platform.isIOS) {
|
||||
return (await plugin.iosInfo).isPhysicalDevice;
|
||||
}
|
||||
return true;
|
||||
return (await AppPlatformInfo.deviceInfo()).isPhysicalDevice;
|
||||
}
|
||||
|
||||
static Future<Map<String, String>> deviceInfo() async {
|
||||
final plugin = DeviceInfoPlugin();
|
||||
if (Platform.isAndroid) {
|
||||
final info = await plugin.androidInfo;
|
||||
return {
|
||||
'platform': 'android',
|
||||
'brand': info.brand,
|
||||
'model': info.model,
|
||||
'systemVersion': info.version.release,
|
||||
};
|
||||
if (!Platform.isAndroid && !Platform.isIOS) {
|
||||
return {'platform': Platform.operatingSystem};
|
||||
}
|
||||
if (Platform.isIOS) {
|
||||
final info = await plugin.iosInfo;
|
||||
return {
|
||||
'platform': 'ios',
|
||||
'brand': info.systemName,
|
||||
'model': info.utsname.machine,
|
||||
'systemVersion': info.systemVersion,
|
||||
};
|
||||
}
|
||||
return {'platform': Platform.operatingSystem};
|
||||
return (await AppPlatformInfo.deviceInfo()).values;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user