diff --git a/packages/smooth_app/lib/database/knowledge_panels_query.dart b/packages/smooth_app/lib/database/knowledge_panels_query.dart index 679c07d2533..d3343f3f52b 100644 --- a/packages/smooth_app/lib/database/knowledge_panels_query.dart +++ b/packages/smooth_app/lib/database/knowledge_panels_query.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:openfoodfacts/model/KnowledgePanels.dart'; import 'package:openfoodfacts/openfoodfacts.dart'; -import 'package:openfoodfacts/utils/QueryType.dart'; +import 'package:openfoodfacts/utils/OpenFoodAPIConfiguration.dart'; import 'package:smooth_app/database/product_query.dart'; class KnowledgePanelsQuery { @@ -18,6 +18,9 @@ class KnowledgePanelsQuery { language: ProductQuery.getLanguage(), country: ProductQuery.getCountry(), ); - return OpenFoodAPIClient.getKnowledgePanels(configuration, QueryType.PROD); + return OpenFoodAPIClient.getKnowledgePanels( + configuration, + OpenFoodAPIConfiguration.globalQueryType, + ); } } diff --git a/packages/smooth_app/lib/database/product_query.dart b/packages/smooth_app/lib/database/product_query.dart index 368dcf746e1..699c7d8d17e 100644 --- a/packages/smooth_app/lib/database/product_query.dart +++ b/packages/smooth_app/lib/database/product_query.dart @@ -1,7 +1,10 @@ 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:smooth_app/data_models/product_list.dart'; +import 'package:smooth_app/data_models/user_preferences.dart'; +import 'package:smooth_app/pages/user_preferences_dev_mode.dart'; abstract class ProductQuery { /// Returns the global language for API queries. @@ -39,6 +42,14 @@ abstract class ProductQuery { comment: 'Test user for project smoothie', ); + /// Sets the query type according to the current [UserPreferences] + static void setQueryType(final UserPreferences userPreferences) => + OpenFoodAPIConfiguration.globalQueryType = userPreferences + .getFlag(UserPreferencesDevMode.userPreferencesFlagProd) ?? + true + ? QueryType.PROD + : QueryType.TEST; + static List get fields => [ ProductField.NAME, ProductField.BRANDS, diff --git a/packages/smooth_app/lib/main.dart b/packages/smooth_app/lib/main.dart index 5709ed6fea6..3720f6eb341 100644 --- a/packages/smooth_app/lib/main.dart +++ b/packages/smooth_app/lib/main.dart @@ -85,6 +85,7 @@ class _SmoothAppState extends State { ProductQuery.setCountry(_userPreferences.userCountryCode); _localDatabase = await LocalDatabase.getLocalDatabase(); _themeProvider = ThemeProvider(_userPreferences); + ProductQuery.setQueryType(_userPreferences); } @override diff --git a/packages/smooth_app/lib/pages/user_preferences_dev_mode.dart b/packages/smooth_app/lib/pages/user_preferences_dev_mode.dart index 7e1c694c95e..b6b8826fc63 100644 --- a/packages/smooth_app/lib/pages/user_preferences_dev_mode.dart +++ b/packages/smooth_app/lib/pages/user_preferences_dev_mode.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:openfoodfacts/utils/OpenFoodAPIConfiguration.dart'; import 'package:smooth_app/data_models/user_preferences.dart'; +import 'package:smooth_app/database/product_query.dart'; import 'package:smooth_app/pages/abstract_user_preferences.dart'; import 'package:smooth_app/pages/onboarding/onboarding_flow_navigator.dart'; @@ -28,6 +30,8 @@ class UserPreferencesDevMode extends AbstractUserPreferences { themeData: themeData, ); + static const String userPreferencesFlagProd = '__devWorkingOnProd'; + @override bool isCollapsedByDefault() => true; @@ -51,7 +55,11 @@ class UserPreferencesDevMode extends AbstractUserPreferences { ListTile( title: const Text('Remove dev mode'), onTap: () async { + // resetting back to "no dev mode" await userPreferences.setDevMode(0); + // resetting back to PROD + await userPreferences.setFlag(userPreferencesFlagProd, true); + ProductQuery.setQueryType(userPreferences); setState(() {}); }, ), @@ -64,5 +72,17 @@ class UserPreferencesDevMode extends AbstractUserPreferences { setState(() {}); }, ), + ListTile( + title: const Text('switch query type'), + subtitle: Text( + 'current value is ${OpenFoodAPIConfiguration.globalQueryType}', + ), + onTap: () async { + await userPreferences.setFlag(userPreferencesFlagProd, + !(userPreferences.getFlag(userPreferencesFlagProd) ?? true)); + ProductQuery.setQueryType(userPreferences); + setState(() {}); + }, + ), ]; }