-
-
Save FredericChang/109f0df23e13c22663818025a80031c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:developer' as developer; | |
import 'dart:io'; | |
import 'package:device_info_plus/device_info_plus.dart'; | |
import 'package:flutter/foundation.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/services.dart'; | |
void main() { | |
runZonedGuarded(() { | |
runApp(const MyApp()); | |
}, (dynamic error, dynamic stack) { | |
developer.log("Something went wrong!", error: error, stackTrace: stack); | |
}); | |
} | |
class MyApp extends StatefulWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
static final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin(); | |
Map<String, dynamic> _deviceData = <String, dynamic>{}; | |
@override | |
void initState() { | |
super.initState(); | |
initPlatformState(); | |
} | |
Future<void> initPlatformState() async { | |
var deviceData = <String, dynamic>{}; | |
try { | |
if (Platform.isAndroid) { | |
deviceData = | |
_readAndroidBuildData(await deviceInfoPlugin.androidInfo); | |
} | |
} on PlatformException { | |
deviceData = <String, dynamic>{ | |
'Error:': 'Failed to get platform version.' | |
}; | |
} | |
if (!mounted) return; | |
setState(() { | |
_deviceData = deviceData; | |
}); | |
} | |
Map<String, dynamic> _readAndroidBuildData(AndroidDeviceInfo build) { | |
print(build.id); | |
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, | |
}; | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text( | |
kIsWeb | |
? 'Web Browser info' | |
: Platform.isAndroid | |
? 'Android Device Info' | |
: Platform.isIOS | |
? 'iOS Device Info' | |
: Platform.isLinux | |
? 'Linux Device Info' | |
: Platform.isMacOS | |
? 'MacOS Device Info' | |
: Platform.isWindows | |
? 'Windows 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(), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment