my_device_info 0.2.0 copy "my_device_info: ^0.2.0" to clipboard
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.

example/lib/main.dart

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),
        ),
      ),
    );
  }
}
1
likes
160
points
116
downloads
screenshot

Documentation

API reference

Publisher

verified publisherwongcoupon.com

Weekly Downloads

Privacy-aware, typed Android and iOS device diagnostics in one call, with an opt-in app-scoped identifier.

Repository (GitHub)
View/report issues

Topics

#device-info #device-identifier #hardware #system-info #flutter-plugin

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on my_device_info

Packages that implement my_device_info