|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- import 'dart:async';
-
- import 'dart:io';
- import 'dart:ui';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:device_info/device_info.dart';
-
-
- class DeviceInfoPage extends StatefulWidget {
- @override
- _DeviceInfoPageState createState() => _DeviceInfoPageState();
- }
-
- class _DeviceInfoPageState extends State<DeviceInfoPage> {
- static final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
- Map<String, dynamic> _deviceData = <String, dynamic>{};
-
- @override
- void initState() {
- super.initState();
- initPlatformState();
- }
-
- Future<void> initPlatformState() async {
- Map<String, dynamic> deviceData;
-
- try {
- if (Platform.isAndroid) {
- deviceData = _readAndroidBuildData(await deviceInfoPlugin.androidInfo);
- } else if (Platform.isIOS) {
- deviceData = _readIosDeviceInfo(await deviceInfoPlugin.iosInfo);
- }
- } on PlatformException {
- deviceData = <String, dynamic>{
- 'Error:': 'Failed to get platform version.'
- };
- }
-
- if (!mounted) return;
-
- setState(() {
- _deviceData = deviceData;
- });
- }
-
- Map<String, dynamic> _readAndroidBuildData(AndroidDeviceInfo build) {
- // 分辨率
- int width = window.physicalSize.width.floor();
- int height = window.physicalSize.height.floor();
-
- return <String, dynamic>{
- 'version.securityPatch': build.version.securityPatch,
- 'version.sdkInt': build.version.sdkInt,
- 'version.release': build.version.release,
- 'version.previewSdkInt': build.version.previewSdkInt,
- 'version.incremental': build.version.incremental,
- 'version.codename': build.version.codename,
- 'version.baseOS': build.version.baseOS,
- 'board': build.board,
- 'bootloader': build.bootloader,
- 'brand': build.brand,
- 'device': build.device,
- 'display': build.display,
- 'fingerprint': build.fingerprint,
- 'hardware': build.hardware,
- 'host': build.host,
- 'id': build.id,
- 'manufacturer': build.manufacturer,
- 'model': build.model,
- 'product': build.product,
- 'supported32BitAbis': build.supported32BitAbis,
- 'supported64BitAbis': build.supported64BitAbis,
- 'supportedAbis': build.supportedAbis,
- 'tags': build.tags,
- 'type': build.type,
- 'isPhysicalDevice': build.isPhysicalDevice,
- 'androidId': build.androidId,
- 'systemFeatures': build.systemFeatures,
- '分辨率': '${width} * ${height}',
- };
- }
-
- Map<String, dynamic> _readIosDeviceInfo(IosDeviceInfo data) {
-
- // 分辨率
- int width = window.physicalSize.width.floor();
- int height = window.physicalSize.height.floor();
-
- return <String, dynamic>{
- 'name': data.name,
- 'systemName': data.systemName,
- 'systemVersion': data.systemVersion,
- 'model': data.model,
- 'localizedModel': data.localizedModel,
- 'identifierForVendor': data.identifierForVendor,
- 'isPhysicalDevice': data.isPhysicalDevice,
- 'utsname.sysname:': data.utsname.sysname,
- 'utsname.nodename:': data.utsname.nodename,
- 'utsname.release:': data.utsname.release,
- 'utsname.version:': data.utsname.version,
- 'utsname.machine:': data.utsname.machine,
- '分辨率': '${width} * ${height}',
- };
- }
-
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- home: Scaffold(
- appBar: AppBar(
- title: Text(
- Platform.isAndroid ? 'Android Device Info' : 'iOS Device Info'),
- ),
- body: ListView(
- children: _deviceData.keys.map((String property) {
- return Row(
- children: <Widget>[
- Container(
- padding: const EdgeInsets.all(10.0),
- child: Text(
- property,
- style: const TextStyle(
- fontWeight: FontWeight.bold,
- ),
- ),
- ),
- Expanded(
- child: Container(
- padding: const EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 10.0),
- child: Text(
- '${_deviceData[property]}',
- maxLines: 10,
- overflow: TextOverflow.ellipsis,
- ),
- )),
- ],
- );
- }).toList(),
- ),
- ),
- );
- }
- }
|