device_identifier 1.0.2+2
device_identifier: ^1.0.2+2 copied to clipboard

A Flutter plugin for iOS and Android to get the unique device identifier.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:device_identifier/device_identifier.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _deviceId = 'Unknown';

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initDeviceIdState() async {
    String deviceId;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      deviceId = await DeviceIdentifier.deviceId;
    } on PlatformException {
      deviceId = 'Failed to get device id.';
    }

    // 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(() {
      _deviceId = deviceId;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Device ID example app'),
        ),
        body: Center(
          child: Text('Running on: $_deviceId\n'),
        ),
      ),
    );
  }
}
2
likes
90
pub points
72%
popularity

A Flutter plugin for iOS and Android to get the unique device identifier.

Repository (GitHub)
View/report issues

Documentation

API reference

License

GPL 3.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on device_identifier