havin_generate_userid

A Flutter plugin for generating and persisting unique random UUIDv4 User IDs securely across Android and iOS.

Features

  • πŸ” Persistent across re-installs (iOS): Saves the generated UUID in iOS Keychain (kSecClassGenericPassword), preserving the User ID even after uninstalling and reinstalling the app.
  • πŸ›‘οΈ Hardware-bound persistence & Zero collisions (Android): Uses DRM Widevine ID (chip level) combined with Settings.Secure.ANDROID_ID and hardware specs to generate a deterministic unique UUID that survives app uninstalls, re-installs, and cache wipes without collisions.
  • πŸ”’ Encrypted Storage: Caches and secures custom/generated IDs using EncryptedSharedPreferences (AES-256) and Auto-Backup.
  • 🎲 Standard UUID Format: Always returns compliant UUID strings.
  • ⚑ Simple API: Easy methods to get, regenerate, custom-set, or clear the User ID.

Getting Started

Add havin_generate_userid to your pubspec.yaml:

dependencies:
  havin_generate_userid: ^1.0.2

Usage

import 'package:havin_generate_userid/havin_generate_userid.dart';

final userIdPlugin = HavinGenerateUserid();

// 1. Get or automatically generate unique User ID
String? userId = await userIdPlugin.getUserId();
print('User ID: $userId');

// 2. Regenerate a new User ID (overwrites existing)
String? newUserId = await userIdPlugin.regenerateUserId();
print('New User ID: $newUserId');

// 3. Set a custom User ID
bool isSet = await userIdPlugin.setUserId('custom-uuid-or-id');

// 4. Clear the User ID from secure storage
bool isCleared = await userIdPlugin.clearUserId();

Platform Details

Platform Storage Mechanism Persistence Across Re-installs & Data Clear
iOS Keychain (kSecClassGenericPassword) Yes (preserved in iOS Keychain)
Android Hardware Seed (DRM Widevine ID + ANDROID_ID) + EncryptedSharedPreferences Yes (hardware-bound deterministic UUID, 100% persistent)