native_device_info 1.0.0 copy "native_device_info: ^1.0.0" to clipboard
native_device_info: ^1.0.0 copied to clipboard

Some commonly used tools in projects.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:native_device_info/native_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> {
  String _platformVersion = 'Unknown';
  String _uuid = 'Unknown';
  String _versionCode = 'Unknown';
  String _versionName = 'Unknown';
  String _appName = 'Unknown';
  String _pkgName = 'Unknown';
  String _userAgent = 'Unknown';
  String _deviceType = 'Unknown';
  String _clientInfo = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      _platformVersion = await NativeDeviceInfo.getPlatformVersion() ??
          'Unknown platform version';
      _uuid = await NativeDeviceInfo.getUUID() ?? 'Unknown UUID';
      _versionCode =
          await NativeDeviceInfo.getVersionCode() ?? 'Unknown Version Code';
      _versionName =
          await NativeDeviceInfo.getVersionName() ?? 'Unknown Version Name';
      _appName = await NativeDeviceInfo.getAppName() ?? 'Unknown App Name';
      _pkgName =
          await NativeDeviceInfo.getPackageName() ?? 'Unknown Package Name';
      _userAgent =
          await NativeDeviceInfo.getUserAgent() ?? 'Unknown User Agent';
      _deviceType =
          await NativeDeviceInfo.getDeviceType() ?? 'Unknown Device Type';
      _clientInfo =
          await NativeDeviceInfo.getClientInfo() ?? 'Unknown Client Info';
    } on PlatformException {}

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text('Running on: $_platformVersion'),
              const SizedBox(height: 5),
              Text('UUID: $_uuid'),
              const SizedBox(height: 5),
              Text('Version Code: $_versionCode'),
              const SizedBox(height: 5),
              Text('Version Name: $_versionName'),
              const SizedBox(height: 5),
              Text('App Name: $_appName'),
              const SizedBox(height: 5),
              Text('Package Name: $_pkgName'),
              const SizedBox(height: 5),
              Text('User Agent: $_userAgent'),
              const SizedBox(height: 5),
              Text('Device Type: $_deviceType'),
              const SizedBox(height: 5),
              Text('Client Info: $_clientInfo'),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
150
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

Some commonly used tools in projects.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on native_device_info

Packages that implement native_device_info