Skip to content
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

Merged
merged 5 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 14 additions & 5 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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be private.


/// Sets the device id as "final variable", for instance for API queries.
Copy link
Contributor

Choose a reason for hiding this comment

The 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A file is missing, right? The one that called setDeviceId...

Copy link
Member Author

Choose a reason for hiding this comment

The 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 ??
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