A Flutter Plugin to Get Unique Id of Mobile Devices

mobile_unique_id

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

Installing

dependencies:
  mobile_unique_id: ^1.0.0

Import

import 'package:mobile_unique_id/mobile_unique_id.dart';

Bugs & Requests

If you encounter any issues, open an issue. Even better, raise a ticket on github for suggestions. Pull request are also welcome.

Flutter

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

License

MIT License

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add mobile_unique_id

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  mobile_unique_id: ^1.0.1

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:mobile_unique_id/mobile_unique_id.dart'; 

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'),
        ),
      ),
    );
  }
} 

Download details:

Author: itsakhiltiwari

Source: https://github.com/itsakhiltiwari/mobile_unique_id

#flutter #mobile 

A Flutter Plugin to Get Unique Id of Mobile Devices
1.00 GEEK