my_device_info 0.1.0
my_device_info: ^0.1.0 copied to clipboard
A Flutter plugin for Android and iOS device details, including an app-scoped identifier, model, OS, CPU, product, and hardware.
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 Map<String, String> details = <String, String>{
'Platform version': await MyDeviceInfo.platformVersion,
'Device identifier': await MyDeviceInfo.deviceIdentifier,
'Device model': await MyDeviceInfo.deviceModel,
'API level': '${await MyDeviceInfo.apiLevel}',
'Manufacturer': await MyDeviceInfo.deviceManufacturer,
'Device name': await MyDeviceInfo.deviceName,
'Product name': await MyDeviceInfo.productName,
'CPU type': await MyDeviceInfo.cpuName,
'Hardware': await MyDeviceInfo.hardware,
};
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),
),
),
);
}
}