基础库
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

144 行
4.3 KiB

  1. import 'dart:async';
  2. import 'dart:io';
  3. import 'dart:ui';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter/services.dart';
  6. import 'package:device_info/device_info.dart';
  7. class DeviceInfoPage extends StatefulWidget {
  8. @override
  9. _DeviceInfoPageState createState() => _DeviceInfoPageState();
  10. }
  11. class _DeviceInfoPageState extends State<DeviceInfoPage> {
  12. static final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
  13. Map<String, dynamic> _deviceData = <String, dynamic>{};
  14. @override
  15. void initState() {
  16. super.initState();
  17. initPlatformState();
  18. }
  19. Future<void> initPlatformState() async {
  20. Map<String, dynamic> deviceData;
  21. try {
  22. if (Platform.isAndroid) {
  23. deviceData = _readAndroidBuildData(await deviceInfoPlugin.androidInfo);
  24. } else if (Platform.isIOS) {
  25. deviceData = _readIosDeviceInfo(await deviceInfoPlugin.iosInfo);
  26. }
  27. } on PlatformException {
  28. deviceData = <String, dynamic>{
  29. 'Error:': 'Failed to get platform version.'
  30. };
  31. }
  32. if (!mounted) return;
  33. setState(() {
  34. _deviceData = deviceData;
  35. });
  36. }
  37. Map<String, dynamic> _readAndroidBuildData(AndroidDeviceInfo build) {
  38. // 分辨率
  39. int width = window.physicalSize.width.floor();
  40. int height = window.physicalSize.height.floor();
  41. return <String, dynamic>{
  42. 'version.securityPatch': build.version.securityPatch,
  43. 'version.sdkInt': build.version.sdkInt,
  44. 'version.release': build.version.release,
  45. 'version.previewSdkInt': build.version.previewSdkInt,
  46. 'version.incremental': build.version.incremental,
  47. 'version.codename': build.version.codename,
  48. 'version.baseOS': build.version.baseOS,
  49. 'board': build.board,
  50. 'bootloader': build.bootloader,
  51. 'brand': build.brand,
  52. 'device': build.device,
  53. 'display': build.display,
  54. 'fingerprint': build.fingerprint,
  55. 'hardware': build.hardware,
  56. 'host': build.host,
  57. 'id': build.id,
  58. 'manufacturer': build.manufacturer,
  59. 'model': build.model,
  60. 'product': build.product,
  61. 'supported32BitAbis': build.supported32BitAbis,
  62. 'supported64BitAbis': build.supported64BitAbis,
  63. 'supportedAbis': build.supportedAbis,
  64. 'tags': build.tags,
  65. 'type': build.type,
  66. 'isPhysicalDevice': build.isPhysicalDevice,
  67. 'androidId': build.androidId,
  68. 'systemFeatures': build.systemFeatures,
  69. '分辨率': '${width} * ${height}',
  70. };
  71. }
  72. Map<String, dynamic> _readIosDeviceInfo(IosDeviceInfo data) {
  73. // 分辨率
  74. int width = window.physicalSize.width.floor();
  75. int height = window.physicalSize.height.floor();
  76. return <String, dynamic>{
  77. 'name': data.name,
  78. 'systemName': data.systemName,
  79. 'systemVersion': data.systemVersion,
  80. 'model': data.model,
  81. 'localizedModel': data.localizedModel,
  82. 'identifierForVendor': data.identifierForVendor,
  83. 'isPhysicalDevice': data.isPhysicalDevice,
  84. 'utsname.sysname:': data.utsname.sysname,
  85. 'utsname.nodename:': data.utsname.nodename,
  86. 'utsname.release:': data.utsname.release,
  87. 'utsname.version:': data.utsname.version,
  88. 'utsname.machine:': data.utsname.machine,
  89. '分辨率': '${width} * ${height}',
  90. };
  91. }
  92. @override
  93. Widget build(BuildContext context) {
  94. return MaterialApp(
  95. home: Scaffold(
  96. appBar: AppBar(
  97. title: Text(
  98. Platform.isAndroid ? 'Android Device Info' : 'iOS Device Info'),
  99. ),
  100. body: ListView(
  101. children: _deviceData.keys.map((String property) {
  102. return Row(
  103. children: <Widget>[
  104. Container(
  105. padding: const EdgeInsets.all(10.0),
  106. child: Text(
  107. property,
  108. style: const TextStyle(
  109. fontWeight: FontWeight.bold,
  110. ),
  111. ),
  112. ),
  113. Expanded(
  114. child: Container(
  115. padding: const EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 10.0),
  116. child: Text(
  117. '${_deviceData[property]}',
  118. maxLines: 10,
  119. overflow: TextOverflow.ellipsis,
  120. ),
  121. )),
  122. ],
  123. );
  124. }).toList(),
  125. ),
  126. ),
  127. );
  128. }
  129. }