-
-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Dart uuid generation #1071
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,12 @@ import 'package:openfoodfacts/openfoodfacts.dart'; | |
import 'package:openfoodfacts/utils/CountryHelper.dart'; | ||
import 'package:openfoodfacts/utils/OpenFoodAPIConfiguration.dart'; | ||
import 'package:openfoodfacts/utils/QueryType.dart'; | ||
import 'package:platform_device_id/platform_device_id.dart'; | ||
import 'package:smooth_app/data_models/product_list.dart'; | ||
import 'package:smooth_app/data_models/user_preferences.dart'; | ||
import 'package:smooth_app/database/dao_string.dart'; | ||
import 'package:smooth_app/database/local_database.dart'; | ||
import 'package:smooth_app/pages/user_preferences_dev_mode.dart'; | ||
import 'package:uuid/uuid.dart'; | ||
|
||
abstract class ProductQuery { | ||
/// Returns the global language for API queries. | ||
|
@@ -40,14 +42,21 @@ abstract class ProductQuery { | |
'_' | ||
'${getCountry()!.iso2Code.toUpperCase()}'; | ||
|
||
/// Device Id, potentially used as API uuid. | ||
static String? deviceId; | ||
static const String UUID_NAME = 'UUID_NAME'; | ||
|
||
/// Sets the device id as "final variable", for instance for API queries. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not "device id" but "uuid" |
||
/// | ||
/// To be called at main / init. | ||
static Future<void> setDeviceId() async => OpenFoodAPIConfiguration.uuid = | ||
deviceId = await PlatformDeviceId.getDeviceId; | ||
static Future<void> setUuid(final LocalDatabase _localDatabase) async { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A file is missing, right? The one that called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just noticed that too |
||
final DaoString uuidString = DaoString(_localDatabase); | ||
String? uuid = await uuidString.get(UUID_NAME); | ||
|
||
if (uuid == null) { | ||
uuid = const Uuid().v4(); | ||
uuidString.put(UUID_NAME, uuid); | ||
} | ||
OpenFoodAPIConfiguration.uuid = uuid; | ||
} | ||
|
||
static User getUser() => | ||
OpenFoodAPIConfiguration.globalUser ?? | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be private.