diff --git a/packages/smooth_app/lib/l10n/app_en.arb b/packages/smooth_app/lib/l10n/app_en.arb index 3d48a96bd50..23619ea5f35 100644 --- a/packages/smooth_app/lib/l10n/app_en.arb +++ b/packages/smooth_app/lib/l10n/app_en.arb @@ -1726,6 +1726,11 @@ "@dev_preferences_import_history_result_success": { "description": "User dev preferences - Import history - Result successful" }, + "dev_mode_section_server": "Server configuration", + "dev_mode_section_product_page": "Product page", + "dev_mode_section_ui": "User Interface", + "dev_mode_section_data": "Data", + "dev_mode_section_experimental_features": "Experimental features", "dev_mode_hide_ecoscore_title": "Exclude Eco-Score", "@dev_mode_hide_ecoscore_title": { "description": "User dev preferences - Disable Ecoscore - Title" diff --git a/packages/smooth_app/lib/pages/preferences/user_preferences_dev_mode.dart b/packages/smooth_app/lib/pages/preferences/user_preferences_dev_mode.dart index 2755008e482..ca57ab676a2 100644 --- a/packages/smooth_app/lib/pages/preferences/user_preferences_dev_mode.dart +++ b/packages/smooth_app/lib/pages/preferences/user_preferences_dev_mode.dart @@ -98,74 +98,35 @@ class UserPreferencesDevMode extends AbstractUserPreferences { value: userPreferences.devMode == 1, ), UserPreferencesItemTile( - title: appLocalizations.dev_preferences_reset_onboarding_title, - subtitle: appLocalizations.dev_preferences_reset_onboarding_subtitle, - onTap: () async { - await userPreferences.resetOnboarding(); - _showSuccessMessage(); - }, + title: 'Debugging information', + onTap: () async => Navigator.of(context).push(MaterialPageRoute( + builder: (BuildContext context) => + const UserPreferencesDebugInfo())), + ), + UserPreferencesItemSection( + label: appLocalizations.dev_mode_section_data, ), UserPreferencesItemTile( - title: appLocalizations.dev_preferences_environment_switch_title, - trailing: DropdownButton( - value: userPreferences.getFlag(userPreferencesFlagProd) ?? true, - elevation: 16, - onChanged: (bool? newValue) async { - await userPreferences.setFlag(userPreferencesFlagProd, newValue); - ProductQuery.setQueryType(userPreferences); - }, - items: const >[ - DropdownMenuItem( - value: true, - child: Text('PROD'), - ), - DropdownMenuItem( - value: false, - child: Text('TEST'), - ), - ], + title: appLocalizations.background_task_title, + subtitle: appLocalizations.background_task_subtitle, + trailing: const BackgroundTaskBadge( + child: Icon(Icons.edit_notifications_outlined), + ), + onTap: () async => Navigator.push( + context, + MaterialPageRoute( + builder: (BuildContext context) => const OfflineTaskPage(), + ), ), ), UserPreferencesItemTile( - title: appLocalizations.dev_preferences_test_environment_title, - subtitle: appLocalizations.dev_preferences_test_environment_subtitle( - ProductQuery.getTestUriProductHelper(userPreferences) - .getPostUri(path: '') - .toString(), + title: appLocalizations.offline_data, + onTap: () => Navigator.push( + context, + MaterialPageRoute( + builder: (BuildContext context) => const OfflineDataPage(), + ), ), - onTap: () async => _changeTestEnvDomain(), - ), - UserPreferencesItemSwitch( - title: appLocalizations.dev_preferences_edit_ingredients_title, - value: userPreferences.getFlag(userPreferencesFlagEditIngredients) ?? - false, - onChanged: (bool value) async { - await userPreferences.setFlag( - userPreferencesFlagEditIngredients, value); - _showSuccessMessage(); - }, - ), - UserPreferencesItemSwitch( - title: 'Accessibility: remove colors', - value: userPreferences - .getFlag(userPreferencesFlagAccessibilityNoColor) ?? - false, - onChanged: (bool value) async { - await userPreferences.setFlag( - userPreferencesFlagAccessibilityNoColor, value); - _showSuccessMessage(); - }, - ), - UserPreferencesItemSwitch( - title: 'Accessibility: show emoji', - value: - userPreferences.getFlag(userPreferencesFlagAccessibilityEmoji) ?? - false, - onChanged: (bool value) async { - await userPreferences.setFlag( - userPreferencesFlagAccessibilityEmoji, value); - _showSuccessMessage(); - }, ), UserPreferencesItemTile( title: appLocalizations.dev_preferences_export_history_title, @@ -235,26 +196,23 @@ class UserPreferencesDevMode extends AbstractUserPreferences { }, ), UserPreferencesItemTile( - title: appLocalizations.offline_data, - onTap: () => Navigator.push( - context, - MaterialPageRoute( - builder: (BuildContext context) => const OfflineDataPage(), - ), - ), + title: 'Refresh all products from server (cf. Nutriscore v2)', + trailing: const Icon(Icons.refresh), + onTap: () async { + final LocalDatabase localDatabase = context.read(); + final DaoProduct daoProduct = DaoProduct(localDatabase); + await daoProduct.clearAllLanguages(); + await BackgroundTaskLanguageRefresh.addTask(localDatabase); + _showSuccessMessage(); + }, ), UserPreferencesItemTile( - title: appLocalizations.background_task_title, - subtitle: appLocalizations.background_task_subtitle, - trailing: const BackgroundTaskBadge( - child: Icon(Icons.edit_notifications_outlined), - ), - onTap: () async => Navigator.push( - context, - MaterialPageRoute( - builder: (BuildContext context) => const OfflineTaskPage(), - ), - ), + // Do not translate + title: 'Reset app language', + onTap: () async { + userPreferences.setAppLanguageCode(null); + ProductQuery.setLanguage(context, userPreferences); + }, ), UserPreferencesItemTile( title: 'Add cards to scanner', @@ -273,6 +231,52 @@ class UserPreferencesDevMode extends AbstractUserPreferences { } }, ), + UserPreferencesItemSection( + label: appLocalizations.dev_mode_section_server, + ), + UserPreferencesItemTile( + title: appLocalizations.dev_preferences_environment_switch_title, + trailing: DropdownButton( + value: userPreferences.getFlag(userPreferencesFlagProd) ?? true, + elevation: 16, + onChanged: (bool? newValue) async { + await userPreferences.setFlag(userPreferencesFlagProd, newValue); + ProductQuery.setQueryType(userPreferences); + }, + items: const >[ + DropdownMenuItem( + value: true, + child: Text('PROD'), + ), + DropdownMenuItem( + value: false, + child: Text('TEST'), + ), + ], + ), + ), + UserPreferencesItemTile( + title: appLocalizations.dev_preferences_test_environment_title, + subtitle: appLocalizations.dev_preferences_test_environment_subtitle( + ProductQuery.getTestUriProductHelper(userPreferences) + .getPostUri(path: '') + .toString(), + ), + onTap: () async => _changeTestEnvDomain(), + ), + UserPreferencesItemSection( + label: appLocalizations.dev_mode_section_product_page, + ), + UserPreferencesItemSwitch( + title: appLocalizations.dev_preferences_edit_ingredients_title, + value: userPreferences.getFlag(userPreferencesFlagEditIngredients) ?? + false, + onChanged: (bool value) async { + await userPreferences.setFlag( + userPreferencesFlagEditIngredients, value); + _showSuccessMessage(); + }, + ), UserPreferencesItemSwitch( title: appLocalizations.dev_mode_hide_ecoscore_title, value: userPreferences @@ -288,41 +292,41 @@ class UserPreferencesDevMode extends AbstractUserPreferences { await userPreferences.setExcludedAttributeIds(list); }, ), + UserPreferencesItemSection( + label: appLocalizations.dev_mode_section_ui, + ), UserPreferencesItemTile( - // Do not translate - title: 'Reset app language', + title: appLocalizations.dev_preferences_reset_onboarding_title, + subtitle: appLocalizations.dev_preferences_reset_onboarding_subtitle, onTap: () async { - userPreferences.setAppLanguageCode(null); - ProductQuery.setLanguage(context, userPreferences); + await userPreferences.resetOnboarding(); + _showSuccessMessage(); }, ), - UserPreferencesItemTile( - title: 'Refresh all products from server (cf. Nutriscore v2)', - trailing: const Icon(Icons.refresh), - onTap: () async { - final LocalDatabase localDatabase = context.read(); - final DaoProduct daoProduct = DaoProduct(localDatabase); - await daoProduct.clearAllLanguages(); - await BackgroundTaskLanguageRefresh.addTask(localDatabase); + UserPreferencesItemSwitch( + title: 'Accessibility: remove colors', + value: userPreferences + .getFlag(userPreferencesFlagAccessibilityNoColor) ?? + false, + onChanged: (bool value) async { + await userPreferences.setFlag( + userPreferencesFlagAccessibilityNoColor, value); _showSuccessMessage(); }, ), UserPreferencesItemSwitch( - title: 'Side by side comparison for 2 or 3 products', + title: 'Accessibility: show emoji', value: - userPreferences.getFlag(userPreferencesFlagBoostedComparison) ?? + userPreferences.getFlag(userPreferencesFlagAccessibilityEmoji) ?? false, onChanged: (bool value) async { await userPreferences.setFlag( - userPreferencesFlagBoostedComparison, value); + userPreferencesFlagAccessibilityEmoji, value); _showSuccessMessage(); }, ), - UserPreferencesItemTile( - title: 'Debugging information', - onTap: () async => Navigator.of(context).push(MaterialPageRoute( - builder: (BuildContext context) => - const UserPreferencesDebugInfo())), + UserPreferencesItemSection( + label: appLocalizations.dev_mode_section_experimental_features, ), UserPreferencesItemSwitch( title: 'User ordered knowledge panels', @@ -391,6 +395,17 @@ class UserPreferencesDevMode extends AbstractUserPreferences { ), ), ), + UserPreferencesItemSwitch( + title: 'Side by side comparison for 2 or 3 products', + value: + userPreferences.getFlag(userPreferencesFlagBoostedComparison) ?? + false, + onChanged: (bool value) async { + await userPreferences.setFlag( + userPreferencesFlagBoostedComparison, value); + _showSuccessMessage(); + }, + ), ]; ScaffoldFeatureController diff --git a/packages/smooth_app/lib/pages/preferences/user_preferences_item.dart b/packages/smooth_app/lib/pages/preferences/user_preferences_item.dart index f7f3f84497c..2e4b90c512d 100644 --- a/packages/smooth_app/lib/pages/preferences/user_preferences_item.dart +++ b/packages/smooth_app/lib/pages/preferences/user_preferences_item.dart @@ -17,5 +17,5 @@ class UserPreferencesItemSimple implements UserPreferencesItem { final Iterable labels; @override - final Widget Function(BuildContext) builder; + final WidgetBuilder builder; } diff --git a/packages/smooth_app/lib/pages/preferences/user_preferences_widgets.dart b/packages/smooth_app/lib/pages/preferences/user_preferences_widgets.dart index 76390f6fdb1..44be303dd28 100644 --- a/packages/smooth_app/lib/pages/preferences/user_preferences_widgets.dart +++ b/packages/smooth_app/lib/pages/preferences/user_preferences_widgets.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:smooth_app/generic_lib/bottom_sheets/smooth_bottom_sheet.dart'; import 'package:smooth_app/generic_lib/design_constants.dart'; import 'package:smooth_app/pages/preferences/user_preferences_item.dart'; +import 'package:smooth_app/themes/smooth_theme_colors.dart'; /// A dashed line class UserPreferencesListItemDivider extends StatelessWidget { @@ -123,7 +124,7 @@ class UserPreferencesItemSwitch implements UserPreferencesItem { ]; @override - Widget Function(BuildContext) get builder => + WidgetBuilder get builder => (final BuildContext context) => UserPreferencesSwitchWidget( title: title, subtitle: subtitle, @@ -154,14 +155,59 @@ class UserPreferencesItemTile implements UserPreferencesItem { ]; @override - Widget Function(BuildContext) get builder => - (final BuildContext context) => ListTile( - title: Text(title), - subtitle: subtitle == null ? null : Text(subtitle!), - onTap: onTap, - leading: leading, - trailing: trailing, - ); + WidgetBuilder get builder => (final BuildContext context) => ListTile( + title: Text(title), + subtitle: subtitle == null ? null : Text(subtitle!), + onTap: onTap, + leading: leading, + trailing: trailing, + ); +} + +class UserPreferencesItemSection implements UserPreferencesItem { + const UserPreferencesItemSection({ + required this.label, + this.icon, + }) : assert(label.length > 0); + + final String label; + final Widget? icon; + + @override + WidgetBuilder get builder => (BuildContext context) { + final SmoothColorsThemeExtension colors = + Theme.of(context).extension()!; + + return Container( + color: colors.primaryDark, + padding: const EdgeInsets.symmetric( + horizontal: LARGE_SPACE, + vertical: SMALL_SPACE, + ), + child: Row( + children: [ + Expanded( + child: Text( + label, + style: TextStyle( + color: colors.primaryLight, + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + ), + if (icon != null) + IconTheme( + data: IconThemeData(color: colors.primaryLight), + child: icon!, + ), + ], + ), + ); + }; + + @override + Iterable get labels => [label]; } /// A preference allowing to choose between a list of items.