mobile_unique_id 1.0.3 copy "mobile_unique_id: ^1.0.3" to clipboard
mobile_unique_id: ^1.0.3 copied to clipboard

A Flutter plugin to get unique id of mobile devices. Supported for Android and iOS platforms.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:mobile_unique_id/mobile_unique_id.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 _uniqueId = 'Unknown';
  final _mobileUniqueIdPlugin = MobileUniqueId();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await _mobileUniqueIdPlugin.getUniqueId() ?? 'NA';
    } on PlatformException {
      platformVersion = 'Failed to get mobile unique 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(() {
      _uniqueId = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('My flutter app'),
        ),
        body: Center(
          child: Text('Mobile has unique id: $_uniqueId\n'),
        ),
      ),
    );
  }
}
2
likes
160
points
184
downloads

Publisher

verified publisherakhiltiwari.com

Weekly Downloads

A Flutter plugin to get unique id of mobile devices. Supported for Android and iOS platforms.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on mobile_unique_id

Packages that implement mobile_unique_id