19 lines
530 B
Dart
19 lines
530 B
Dart
import 'package:analytics_sdk/utils/platform_storage.dart';
|
|
import 'package:analytics_sdk/utils/uuid_util.dart';
|
|
|
|
const _kDeviceIdStorageKey = 'analytics_device_id';
|
|
|
|
Future<String> generateOrLoadDeviceId() async {
|
|
try {
|
|
final existing =
|
|
(await PlatformStorage.read(_kDeviceIdStorageKey))?.trim() ?? '';
|
|
if (existing.isNotEmpty) return existing;
|
|
|
|
final generated = generateUuidV4();
|
|
await PlatformStorage.write(_kDeviceIdStorageKey, generated);
|
|
return generated;
|
|
} catch (_) {
|
|
return '';
|
|
}
|
|
}
|