setUuid static method
- LocalDatabase localDatabase
Sets the uuid id as "final variable", for instance for API queries.
To be called at main / init.
Implementation
static Future<void> setUuid(LocalDatabase localDatabase) async {
final DaoString uuidString = DaoString(localDatabase);
String? uuid = await uuidString.get(_UUID_NAME);
if (uuid == null) {
// Crop down to 16 letters for matomo
uuid = const Uuid().v4().replaceAll('-', '').substring(0, 16);
await uuidString.put(_UUID_NAME, uuid);
}
OpenFoodAPIConfiguration.uuid = uuid;
await Sentry.configureScope((Scope scope) {
scope.contexts['uuid'] = OpenFoodAPIConfiguration.uuid;
scope.setUser(SentryUser(username: OpenFoodAPIConfiguration.uuid));
});
}