Skip to content

Commit

Permalink
fix: Dart uuid generation (#1071)
Browse files Browse the repository at this point in the history
* fix: Dart uuid generation

* Update product_query.dart

* Update product_query.dart

* fix

* Update product_query.dart
  • Loading branch information
M123-dev authored Feb 5, 2022
1 parent d2c6217 commit 5c68cfc
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -412,7 +412,7 @@ Future<void> saveAnswer(
future: OpenFoodAPIClient.postInsightAnnotation(
insightId,
insightAnnotation,
deviceId: ProductQuery.deviceId,
deviceId: OpenFoodAPIConfiguration.uuid,
),
title: appLocalizations.saving_answer,
);
Expand Down
21 changes: 15 additions & 6 deletions packages/smooth_app/lib/database/product_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<void> setDeviceId() async => OpenFoodAPIConfiguration.uuid =
deviceId = await PlatformDeviceId.getDeviceId;
static Future<void> 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 ??
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class _SmoothAppState extends State<SmoothApp> {

UserManagementHelper.mountCredentials();
cameras = await availableCameras();
await ProductQuery.setDeviceId();
await ProductQuery.setUuid(_localDatabase);
}

@override
Expand Down
58 changes: 1 addition & 57 deletions packages/smooth_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5c68cfc

Please sign in to comment.