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/database/product_query.dart b/packages/smooth_app/lib/database/product_query.dart index 2947903ee01..1af38bba608 100644 --- a/packages/smooth_app/lib/database/product_query.dart +++ b/packages/smooth_app/lib/database/product_query.dart @@ -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. + /// Sets the uuid 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 setUuid(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); + } + OpenFoodAPIConfiguration.uuid = uuid; + } static User getUser() => OpenFoodAPIConfiguration.globalUser ?? diff --git a/packages/smooth_app/lib/main.dart b/packages/smooth_app/lib/main.dart index 9ac339615dc..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(); + await ProductQuery.setUuid(_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