unique_device_identifier 2.0.4 copy "unique_device_identifier: ^2.0.4" to clipboard
unique_device_identifier: ^2.0.4 copied to clipboard

A Flutter plugin that provides a unique device identifier on all platforms including Android, iOS, Windows, macOS, Linux, Web.

unique_device_identifier #

A Flutter plugin that provides a unique device identifier on all platforms including Android, iOS, Windows, macOS, Linux, Web.


✨ Features #

  • πŸ“± Android: Uses Settings.Secure.ANDROID_ID
  • 🍎 iOS: Uses UIDevice.identifierForVendor
  • πŸ’» macOS: Uses IOPlatformUUID via IOKit
    • Automatically uses kIOMainPortDefault on macOS 12+ (no deprecation warning)
    • Falls back to kIOMasterPortDefault for compatibility with macOS 11 and earlier
  • 🐧 Linux: Reads /etc/machine-id
  • πŸͺŸ Windows: Reads registry value MachineGuid
  • 🌐 Web:
    • Attempts to read a UUID from window.localStorage
    • If the value is missing or invalid, it tries to generate one based on browser fingerprint
    • If fingerprinting fails, generates a new UUID using Dart code (generateUUID)
    • The newly generated UUID is stored in localStorage for future reuse
    • Ensures the same UUID persists across reloads and sessions

πŸš€ Getting Started #

Add the dependency to your pubspec.yaml:

dependencies:
  unique_device_identifier: ^2.0.4

βœ… Usage #

import 'package:unique_device_identifier/unique_device_identifier.dart';

void main() async {
  final String? deviceId = await UniqueDeviceIdentifier.getUniqueIdentifier();
  print("Device ID: $deviceId");
}

πŸ“¦ Supported Platforms #

Platform Method
Android Settings.Secure.ANDROID_ID
iOS UIDevice.identifierForVendor
macOS IOPlatformUUID (via IOKit with macOS version fallback)
Linux /etc/machine-id
Windows Registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\MachineGuid
Web Attempts to read a UUID from localStorage. If not found or invalid, it tries to generate one using a browser fingerprint. If that fails, it generates a new UUID using crypto.randomUUID. The newly generated UUID is then stored in localStorage for future reuse.

πŸ”’ Notes #

  • On iOS and Android, the UUID may change after uninstalling and reinstalling the app.
  • macOS implementation avoids deprecated APIs on macOS 12+.
  • On Web, the UUID is first read from localStorage. If it is missing or invalid, the plugin attempts to generate one using a browser fingerprint. If that fails, it falls back to a randomly generated UUID using Dart code. The final UUID is then stored in localStorage for future reuse and can be manually cleared by the user through the browser's storage settings.

πŸ›  Development #

This plugin uses MethodChannel to communicate with native code.

Each platform implements get_unique_identifier using platform-specific APIs, and the Web implementation is written in Dart using dart:js_interop.


πŸ“„ License #

MIT License

6
likes
140
points
328
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin that provides a unique device identifier on all platforms including Android, iOS, Windows, macOS, Linux, Web.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface, web

More

Packages that depend on unique_device_identifier

Packages that implement unique_device_identifier