From 8569ff16c0f9c48a4b7628dc83ea996c349dace4 Mon Sep 17 00:00:00 2001 From: M123-dev Date: Sat, 5 Feb 2022 12:32:51 +0100 Subject: [PATCH 1/5] fix: Dart uuid generation --- .../lib/database/product_query.dart | 20 ++++++- packages/smooth_app/lib/main.dart | 2 +- packages/smooth_app/pubspec.lock | 58 +------------------ packages/smooth_app/pubspec.yaml | 2 +- 4 files changed, 20 insertions(+), 62 deletions(-) diff --git a/packages/smooth_app/lib/database/product_query.dart b/packages/smooth_app/lib/database/product_query.dart index 2947903ee01..688646cb6e6 100644 --- a/packages/smooth_app/lib/database/product_query.dart +++ b/packages/smooth_app/lib/database/product_query.dart @@ -2,10 +2,13 @@ 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/pages/user_preferences_dev_mode.dart'; +import 'package:uuid/uuid.dart'; + +import 'local_database.dart'; abstract class ProductQuery { /// Returns the global language for API queries. @@ -42,12 +45,23 @@ abstract class ProductQuery { /// 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. /// /// To be called at main / init. - static Future setDeviceId() async => OpenFoodAPIConfiguration.uuid = - deviceId = await PlatformDeviceId.getDeviceId; + static Future setDeviceId(final LocalDatabase _localDatabase) async { + final DaoString uuidString = DaoString(_localDatabase); + String? uuid = await uuidString.get(UUID_NAME); + + if (uuid == null) { + uuid = const Uuid().v4(); + uuidString.put(UUID_NAME, uuid); + } + print('M123: ${uuid}'); + OpenFoodAPIConfiguration.uuid = uuid; + deviceId = uuid; + } static User getUser() => OpenFoodAPIConfiguration.globalUser ?? diff --git a/packages/smooth_app/lib/main.dart b/packages/smooth_app/lib/main.dart index 9ac339615dc..d5afb58c0e8 100644 --- a/packages/smooth_app/lib/main.dart +++ b/packages/smooth_app/lib/main.dart @@ -97,7 +97,7 @@ class _SmoothAppState extends State { UserManagementHelper.mountCredentials(); cameras = await availableCameras(); - await ProductQuery.setDeviceId(); + await ProductQuery.setDeviceId(_localDatabase); } @override diff --git a/packages/smooth_app/pubspec.lock b/packages/smooth_app/pubspec.lock index 358ed7bc767..5e11e43b9a8 100644 --- a/packages/smooth_app/pubspec.lock +++ b/packages/smooth_app/pubspec.lock @@ -197,20 +197,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.0" - device_info: - dependency: transitive - description: - name: device_info - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.3" - device_info_platform_interface: - dependency: transitive - description: - name: device_info_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.1" device_preview: dependency: "direct main" description: @@ -742,48 +728,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.0" - platform_device_id: - dependency: "direct main" - description: - name: platform_device_id - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.1" - platform_device_id_linux: - dependency: transitive - description: - name: platform_device_id_linux - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - platform_device_id_macos: - dependency: transitive - description: - name: platform_device_id_macos - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - platform_device_id_platform_interface: - dependency: transitive - description: - name: platform_device_id_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - platform_device_id_web: - dependency: transitive - description: - name: platform_device_id_web - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - platform_device_id_windows: - dependency: transitive - description: - name: platform_device_id_windows - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" plugin_platform_interface: dependency: transitive description: @@ -1077,7 +1021,7 @@ packages: source: hosted version: "2.0.2" uuid: - dependency: transitive + dependency: "direct main" description: name: uuid url: "https://pub.dartlang.org" diff --git a/packages/smooth_app/pubspec.yaml b/packages/smooth_app/pubspec.yaml index e060e1af008..58b7d55dc65 100644 --- a/packages/smooth_app/pubspec.yaml +++ b/packages/smooth_app/pubspec.yaml @@ -33,7 +33,7 @@ dependencies: package_info_plus: ^1.3.0 permission_handler: ^8.3.0 photo_view: ^0.13.0 - platform_device_id: ^1.0.1 + uuid: ^3.0.5 provider: ^6.0.2 qr_code_scanner: ^0.6.1 rubber: ^1.0.1 From 30d4acd7eefa1c346992a118f6ec173292bf2c3c Mon Sep 17 00:00:00 2001 From: M123-dev Date: Sat, 5 Feb 2022 12:34:04 +0100 Subject: [PATCH 2/5] Update product_query.dart --- packages/smooth_app/lib/database/product_query.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/smooth_app/lib/database/product_query.dart b/packages/smooth_app/lib/database/product_query.dart index 688646cb6e6..ff63e4ea4ff 100644 --- a/packages/smooth_app/lib/database/product_query.dart +++ b/packages/smooth_app/lib/database/product_query.dart @@ -58,7 +58,6 @@ abstract class ProductQuery { uuid = const Uuid().v4(); uuidString.put(UUID_NAME, uuid); } - print('M123: ${uuid}'); OpenFoodAPIConfiguration.uuid = uuid; deviceId = uuid; } From 978b463777ae24d18e170f6ce791f1e9fb7fd9a7 Mon Sep 17 00:00:00 2001 From: M123-dev Date: Sat, 5 Feb 2022 15:15:52 +0100 Subject: [PATCH 3/5] Update product_query.dart --- packages/smooth_app/lib/database/product_query.dart | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/smooth_app/lib/database/product_query.dart b/packages/smooth_app/lib/database/product_query.dart index ff63e4ea4ff..e5375369a4a 100644 --- a/packages/smooth_app/lib/database/product_query.dart +++ b/packages/smooth_app/lib/database/product_query.dart @@ -5,11 +5,10 @@ import 'package:openfoodfacts/utils/QueryType.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'; -import 'local_database.dart'; - abstract class ProductQuery { /// Returns the global language for API queries. static OpenFoodFactsLanguage? getLanguage() { @@ -43,14 +42,12 @@ 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. /// /// To be called at main / init. - static Future setDeviceId(final LocalDatabase _localDatabase) async { + static Future setUuid(final LocalDatabase _localDatabase) async { final DaoString uuidString = DaoString(_localDatabase); String? uuid = await uuidString.get(UUID_NAME); @@ -59,7 +56,6 @@ abstract class ProductQuery { uuidString.put(UUID_NAME, uuid); } OpenFoodAPIConfiguration.uuid = uuid; - deviceId = uuid; } static User getUser() => From 417c05a691d4db31f818d97dd432aca50586b6d5 Mon Sep 17 00:00:00 2001 From: M123-dev Date: Sat, 5 Feb 2022 15:17:50 +0100 Subject: [PATCH 4/5] fix --- .../smooth_app/lib/cards/product_cards/question_card.dart | 4 ++-- packages/smooth_app/lib/main.dart | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/smooth_app/lib/cards/product_cards/question_card.dart b/packages/smooth_app/lib/cards/product_cards/question_card.dart index e5e6b5186d2..f35f890654f 100644 --- a/packages/smooth_app/lib/cards/product_cards/question_card.dart +++ b/packages/smooth_app/lib/cards/product_cards/question_card.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:openfoodfacts/openfoodfacts.dart'; +import 'package:openfoodfacts/utils/OpenFoodAPIConfiguration.dart'; import 'package:smooth_app/cards/product_cards/product_image_carousel.dart'; import 'package:smooth_app/cards/product_cards/product_title_card.dart'; -import 'package:smooth_app/database/product_query.dart'; import 'package:smooth_app/helpers/ui_helpers.dart'; import 'package:smooth_app/helpers/user_management_helper.dart'; import 'package:smooth_app/pages/user_management/login_page.dart'; @@ -412,7 +412,7 @@ Future saveAnswer( future: OpenFoodAPIClient.postInsightAnnotation( insightId, insightAnnotation, - deviceId: ProductQuery.deviceId, + deviceId: OpenFoodAPIConfiguration.uuid, ), title: appLocalizations.saving_answer, ); diff --git a/packages/smooth_app/lib/main.dart b/packages/smooth_app/lib/main.dart index d5afb58c0e8..a86fef71a93 100644 --- a/packages/smooth_app/lib/main.dart +++ b/packages/smooth_app/lib/main.dart @@ -97,7 +97,7 @@ class _SmoothAppState extends State { UserManagementHelper.mountCredentials(); cameras = await availableCameras(); - await ProductQuery.setDeviceId(_localDatabase); + await ProductQuery.setUuid(_localDatabase); } @override From d154aa0cec436eff7cda4e7272c508bf6ce6b271 Mon Sep 17 00:00:00 2001 From: M123-dev Date: Sat, 5 Feb 2022 15:23:16 +0100 Subject: [PATCH 5/5] Update product_query.dart --- packages/smooth_app/lib/database/product_query.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/smooth_app/lib/database/product_query.dart b/packages/smooth_app/lib/database/product_query.dart index e5375369a4a..1af38bba608 100644 --- a/packages/smooth_app/lib/database/product_query.dart +++ b/packages/smooth_app/lib/database/product_query.dart @@ -42,18 +42,18 @@ abstract class ProductQuery { '_' '${getCountry()!.iso2Code.toUpperCase()}'; - static const String UUID_NAME = 'UUID_NAME'; + static const String _UUID_NAME = 'UUID_NAME'; - /// Sets the device id as "final variable", for instance for API queries. + /// Sets the uuid id as "final variable", for instance for API queries. /// /// To be called at main / init. static Future setUuid(final LocalDatabase _localDatabase) async { final DaoString uuidString = DaoString(_localDatabase); - String? uuid = await uuidString.get(UUID_NAME); + String? uuid = await uuidString.get(_UUID_NAME); if (uuid == null) { uuid = const Uuid().v4(); - uuidString.put(UUID_NAME, uuid); + uuidString.put(_UUID_NAME, uuid); } OpenFoodAPIConfiguration.uuid = uuid; }