From 6c43387a6de4170215e4dde106995583e52fbafa Mon Sep 17 00:00:00 2001 From: Abu Date: Mon, 20 Feb 2023 05:07:47 +0530 Subject: [PATCH] using OpenFoodAPIConfiguration uuid --- .../lib/helpers/network_config.dart | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/smooth_app/lib/helpers/network_config.dart b/packages/smooth_app/lib/helpers/network_config.dart index 5795acfad3f..9a51524ca4e 100644 --- a/packages/smooth_app/lib/helpers/network_config.dart +++ b/packages/smooth_app/lib/helpers/network_config.dart @@ -5,6 +5,7 @@ import 'package:flutter/services.dart'; import 'package:openfoodfacts/openfoodfacts.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:smooth_app/helpers/app_helper.dart'; +import 'package:uuid/uuid.dart'; /// Initializes both the user agent && the SSL certificate Future setupAppNetworkConfig() async { @@ -12,6 +13,16 @@ Future setupAppNetworkConfig() async { return _importSSLCertificate(); } +String _getUuidId() { + if (OpenFoodAPIConfiguration.uuid != null) { + return OpenFoodAPIConfiguration.uuid!; + } + + const Uuid uuid = Uuid(); + OpenFoodAPIConfiguration.uuid = uuid.v4(); + return OpenFoodAPIConfiguration.uuid!; +} + Future _initUserAgent() async { final PackageInfo packageInfo = await PackageInfo.fromPlatform(); @@ -19,10 +30,12 @@ Future _initUserAgent() async { final String version = '${packageInfo.version}+${packageInfo.buildNumber}'; final String system = '${Platform.operatingSystem}+${Platform.operatingSystemVersion}'; + final String id = _getUuidId(); final String comment = _getAppInfoComment( name: name, version: version, system: system, + id: id, ); OpenFoodAPIConfiguration.userAgent = UserAgent( name: name, @@ -39,6 +52,8 @@ String _getAppInfoComment({ String version = '', bool withSystem = true, String system = '', + bool withId = true, + String id = '', }) { String appInfo = ''; const String infoDelimiter = ' - '; @@ -54,6 +69,10 @@ String _getAppInfoComment({ appInfo += infoDelimiter; appInfo += system; } + if (withId) { + appInfo += infoDelimiter; + appInfo += id; + } return appInfo; }