16 lines
444 B
Dart
16 lines
444 B
Dart
import 'package:uuid/uuid.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class DeviceIdService {
|
|
static const _uuidKey = 'device_uuid';
|
|
|
|
static Future<String> getOrCreateUUID() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
String? uuid = prefs.getString(_uuidKey);
|
|
if (uuid == null) {
|
|
uuid = const Uuid().v4();
|
|
await prefs.setString(_uuidKey, uuid);
|
|
}
|
|
return uuid;
|
|
}
|
|
}
|