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

feat: Dev mode with sections + reordered #5372

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
215 changes: 115 additions & 100 deletions packages/smooth_app/lib/pages/preferences/user_preferences_dev_mode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>(
builder: (BuildContext context) =>
const UserPreferencesDebugInfo())),
),
UserPreferencesItemSection(
label: appLocalizations.dev_mode_section_data,
),
UserPreferencesItemTile(
title: appLocalizations.dev_preferences_environment_switch_title,
trailing: DropdownButton<bool>(
value: userPreferences.getFlag(userPreferencesFlagProd) ?? true,
elevation: 16,
onChanged: (bool? newValue) async {
await userPreferences.setFlag(userPreferencesFlagProd, newValue);
ProductQuery.setQueryType(userPreferences);
},
items: const <DropdownMenuItem<bool>>[
DropdownMenuItem<bool>(
value: true,
child: Text('PROD'),
),
DropdownMenuItem<bool>(
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<void>(
context,
MaterialPageRoute<void>(
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<void>(
context,
MaterialPageRoute<void>(
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,
Expand Down Expand Up @@ -235,26 +196,23 @@ class UserPreferencesDevMode extends AbstractUserPreferences {
},
),
UserPreferencesItemTile(
title: appLocalizations.offline_data,
onTap: () => Navigator.push<void>(
context,
MaterialPageRoute<void>(
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<LocalDatabase>();
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<void>(
context,
MaterialPageRoute<void>(
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',
Expand All @@ -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<bool>(
value: userPreferences.getFlag(userPreferencesFlagProd) ?? true,
elevation: 16,
onChanged: (bool? newValue) async {
await userPreferences.setFlag(userPreferencesFlagProd, newValue);
ProductQuery.setQueryType(userPreferences);
},
items: const <DropdownMenuItem<bool>>[
DropdownMenuItem<bool>(
value: true,
child: Text('PROD'),
),
DropdownMenuItem<bool>(
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
Expand All @@ -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<LocalDatabase>();
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<void>(
builder: (BuildContext context) =>
const UserPreferencesDebugInfo())),
UserPreferencesItemSection(
label: appLocalizations.dev_mode_section_experimental_features,
),
UserPreferencesItemSwitch(
title: 'User ordered knowledge panels',
Expand Down Expand Up @@ -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<SnackBar, SnackBarClosedReason>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ class UserPreferencesItemSimple implements UserPreferencesItem {
final Iterable<String> labels;

@override
final Widget Function(BuildContext) builder;
final WidgetBuilder builder;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<SmoothColorsThemeExtension>()!;

return Container(
color: colors.primaryDark,
padding: const EdgeInsets.symmetric(
horizontal: LARGE_SPACE,
vertical: SMALL_SPACE,
),
child: Row(
children: <Widget>[
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<String> get labels => <String>[label];
}

/// A preference allowing to choose between a list of items.
Expand Down