my_device_info 0.2.0
my_device_info: ^0.2.0 copied to clipboard
Privacy-aware, typed Android and iOS device diagnostics in one call, with an opt-in app-scoped identifier.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:my_device_info/my_device_info.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Map<String, String> _details = const <String, String>{};
String? _error;
@override
void initState() {
super.initState();
_loadDeviceInfo();
}
Future<void> _loadDeviceInfo() async {
try {
final DeviceInfoSnapshot info = await MyDeviceInfo.getInfo();
final Map<String, String> details = <String, String>{
'Platform': info.platform.name,
'OS version':
'${info.operatingSystem.name} ${info.operatingSystem.version}',
if (info.operatingSystem.androidApiLevel case final int apiLevel)
'Android API level': '$apiLevel',
'Device model': info.model,
'Model identifier': info.modelIdentifier,
'Manufacturer': info.manufacturer,
'Device name': info.deviceName,
'Product name': info.productName,
'Architecture': info.architecture,
'Supported ABIs': info.supportedAbis.join(', '),
'Hardware': info.hardware,
'Device type': info.isPhysicalDevice
? 'Physical device'
: 'Emulator or simulator',
if (info.isLowRamDevice case final bool isLowRam)
'Low-RAM device': '$isLowRam',
};
if (!mounted) {
return;
}
setState(() {
_details = details;
_error = null;
});
} on PlatformException catch (error) {
if (!mounted) {
return;
}
setState(() {
_error = error.message ?? error.code;
});
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('My Device Info')),
body: _error == null
? ListView(
children: _details.entries
.map(
(MapEntry<String, String> entry) => ListTile(
title: Text(entry.key),
subtitle: Text(entry.value),
),
)
.toList(),
)
: Center(child: Text('Unable to read device info: $_error')),
floatingActionButton: FloatingActionButton(
onPressed: _loadDeviceInfo,
tooltip: 'Reload',
child: const Icon(Icons.refresh),
),
),
);
}
}