getDeviceIdentity method

  1. @override
Future<DeviceIdentity> getDeviceIdentity()
override

Returns the current device identity

Implementation

@override
Future<DeviceIdentity> getDeviceIdentity() async {
  // 1️⃣ Check if already stored locally
  final storedId = await _storage.read(key: _storageKey);
  if (storedId != null) {
    return _buildDeviceIdentity(storedId);
  }

  // 2️⃣ Generate platform-specific ID
  String platformId;
  if (Platform.isAndroid) {
    platformId = await const AndroidId().getId() ?? _uuid.v4();
  } else if (Platform.isIOS) {
    final iosInfo = await DeviceInfoPlugin().iosInfo;
    platformId = iosInfo.identifierForVendor ?? _uuid.v4();
  } else {
    platformId = _uuid.v4(); // fallback for web/desktop
  }

  // 3️⃣ Persist UUID locally (best-effort persistence)
  await _storage.write(key: _storageKey, value: platformId);

  return _buildDeviceIdentity(platformId);
}