diff --git a/packages/smooth_app/lib/cards/data_cards/svg_icon_chip.dart b/packages/smooth_app/lib/cards/data_cards/svg_icon_chip.dart index a76c163d91c..0c0af7d78b2 100644 --- a/packages/smooth_app/lib/cards/data_cards/svg_icon_chip.dart +++ b/packages/smooth_app/lib/cards/data_cards/svg_icon_chip.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:smooth_app/cards/category_cards/svg_cache.dart'; diff --git a/packages/smooth_app/lib/data_models/user_preferences.dart b/packages/smooth_app/lib/data_models/user_preferences.dart index 6c049e376c3..57a0b8f3a4e 100644 --- a/packages/smooth_app/lib/data_models/user_preferences.dart +++ b/packages/smooth_app/lib/data_models/user_preferences.dart @@ -23,6 +23,7 @@ class UserPreferences extends ChangeNotifier { static const String _TAG_LAST_VISITED_ONBOARDING_PAGE = 'lastVisitedOnboardingPage'; static const String _TAG_PREFIX_FLAG = 'FLAG_PREFIX_'; + static const String _TAG_DEV_MODE = 'devMode'; Future init(final ProductPreferences productPreferences) async { if (_sharedPreferences.getBool(_TAG_INIT) != null) { @@ -91,4 +92,9 @@ class UserPreferences extends ChangeNotifier { bool? getFlag(final String key) => _sharedPreferences.getBool(_getFlagTag(key)); + + Future setDevMode(final int value) async => + _sharedPreferences.setInt(_TAG_DEV_MODE, value); + + int get devMode => _sharedPreferences.getInt(_TAG_DEV_MODE) ?? 0; } diff --git a/packages/smooth_app/lib/helpers/attributes_card_helper.dart b/packages/smooth_app/lib/helpers/attributes_card_helper.dart index fa83445ed2f..664c89abfc6 100644 --- a/packages/smooth_app/lib/helpers/attributes_card_helper.dart +++ b/packages/smooth_app/lib/helpers/attributes_card_helper.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:openfoodfacts/model/Attribute.dart'; diff --git a/packages/smooth_app/lib/helpers/product_cards_helper.dart b/packages/smooth_app/lib/helpers/product_cards_helper.dart index a7847bb1c61..33a3233116c 100644 --- a/packages/smooth_app/lib/helpers/product_cards_helper.dart +++ b/packages/smooth_app/lib/helpers/product_cards_helper.dart @@ -1,4 +1,4 @@ -import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:openfoodfacts/model/Attribute.dart'; diff --git a/packages/smooth_app/lib/helpers/score_card_helper.dart b/packages/smooth_app/lib/helpers/score_card_helper.dart index 048b477858c..9b83f6d43b9 100644 --- a/packages/smooth_app/lib/helpers/score_card_helper.dart +++ b/packages/smooth_app/lib/helpers/score_card_helper.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:openfoodfacts/model/Attribute.dart'; import 'package:openfoodfacts/model/KnowledgePanel.dart'; diff --git a/packages/smooth_app/lib/pages/user_management/forgot_password_page.dart b/packages/smooth_app/lib/pages/user_management/forgot_password_page.dart index 99614a944f8..f4b75a93691 100644 --- a/packages/smooth_app/lib/pages/user_management/forgot_password_page.dart +++ b/packages/smooth_app/lib/pages/user_management/forgot_password_page.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:openfoodfacts/openfoodfacts.dart'; import 'package:provider/provider.dart'; +import 'package:smooth_app/data_models/user_preferences.dart'; import 'package:smooth_app/themes/theme_provider.dart'; import 'package:smooth_ui_library/widgets/smooth_card.dart'; import 'package:smooth_ui_library/widgets/smooth_text_form_field.dart'; @@ -14,6 +15,8 @@ class ForgotPasswordPage extends StatefulWidget { } class _ForgotPasswordPageState extends State { + int _devModeCounter = 0; + static Color _textFieldBackgroundColor = const Color.fromARGB( 255, 240, @@ -65,6 +68,7 @@ class _ForgotPasswordPageState extends State { final ThemeData theme = Theme.of(context); final ThemeProvider themeProvider = context.watch(); final AppLocalizations appLocalizations = AppLocalizations.of(context)!; + final UserPreferences userPreferences = context.watch(); final Size size = MediaQuery.of(context).size; // Needs to be changed @@ -136,6 +140,30 @@ class _ForgotPasswordPageState extends State { ], validator: (String? value) { if (value == null || value.isEmpty) { + _devModeCounter++; + if (_devModeCounter >= 10) { + if (userPreferences.devMode == 0) { + showDialog( + context: context, + builder: (BuildContext context) => AlertDialog( + title: const Text('Ready for the dev mode?'), + actions: [ + TextButton( + child: Text(appLocalizations.yes), + onPressed: () async { + await userPreferences.setDevMode(1); + Navigator.pop(context); + }, + ), + TextButton( + child: Text(appLocalizations.no), + onPressed: () => Navigator.pop(context), + ) + ], + ), + ); + } + } return appLocalizations.enter_some_text; } return null; diff --git a/packages/smooth_app/lib/pages/user_preferences_dev_mode.dart b/packages/smooth_app/lib/pages/user_preferences_dev_mode.dart new file mode 100644 index 00000000000..7e1c694c95e --- /dev/null +++ b/packages/smooth_app/lib/pages/user_preferences_dev_mode.dart @@ -0,0 +1,68 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:smooth_app/data_models/user_preferences.dart'; +import 'package:smooth_app/pages/abstract_user_preferences.dart'; +import 'package:smooth_app/pages/onboarding/onboarding_flow_navigator.dart'; + +/// Collapsed/expanded display of "dev mode" for the preferences page. +/// +/// The dev mode is triggered this way: +/// * go to the "forgotten password" page +/// * click 10 times on the action button (in French "Changer le mot de passe") +/// * you'll see a dialog; obviously click "yes" +/// * go to the preferences page +/// * expand/collapse any item +/// * then you'll see the dev mode in red +class UserPreferencesDevMode extends AbstractUserPreferences { + UserPreferencesDevMode({ + required final Function(Function()) setState, + required final BuildContext context, + required final UserPreferences userPreferences, + required final AppLocalizations appLocalizations, + required final ThemeData themeData, + }) : super( + setState: setState, + context: context, + userPreferences: userPreferences, + appLocalizations: appLocalizations, + themeData: themeData, + ); + + @override + bool isCollapsedByDefault() => true; + + @override + String getPreferenceFlagKey() => 'devMode'; + + @override + Widget getTitle() => Container( + color: Colors.red, + child: Text( + 'DEV MODE', + style: themeData.textTheme.headline2!.copyWith(color: Colors.white), + ), + ); + + @override + Widget? getSubtitle() => null; + + @override + List getBody() => [ + ListTile( + title: const Text('Remove dev mode'), + onTap: () async { + await userPreferences.setDevMode(0); + setState(() {}); + }, + ), + ListTile( + title: const Text('restart onboarding'), + subtitle: const Text('then you have to restart flutter'), + onTap: () async { + userPreferences + .setLastVisitedOnboardingPage(OnboardingPage.NOT_STARTED); + setState(() {}); + }, + ), + ]; +} diff --git a/packages/smooth_app/lib/pages/user_preferences_page.dart b/packages/smooth_app/lib/pages/user_preferences_page.dart index 3851606ed89..fcb792564cd 100644 --- a/packages/smooth_app/lib/pages/user_preferences_page.dart +++ b/packages/smooth_app/lib/pages/user_preferences_page.dart @@ -4,6 +4,7 @@ import 'package:provider/provider.dart'; import 'package:smooth_app/data_models/product_preferences.dart'; import 'package:smooth_app/data_models/user_preferences.dart'; import 'package:smooth_app/pages/abstract_user_preferences.dart'; +import 'package:smooth_app/pages/user_preferences_dev_mode.dart'; import 'package:smooth_app/pages/user_preferences_food.dart'; import 'package:smooth_app/pages/user_preferences_profile.dart'; import 'package:smooth_app/pages/user_preferences_settings.dart'; @@ -52,6 +53,17 @@ class _UserPreferencesPageState extends State { themeData: themeData, ), ]; + if (userPreferences.devMode > 0) { + items.add( + UserPreferencesDevMode( + setState: setState, + context: context, + userPreferences: userPreferences, + appLocalizations: appLocalizations, + themeData: themeData, + ), + ); + } final List children = []; for (final AbstractUserPreferences abstractUserPreferences in items) { children.addAll(abstractUserPreferences.getContent()); diff --git a/packages/smooth_ui_library/lib/animations/smooth_reveal_animation.dart b/packages/smooth_ui_library/lib/animations/smooth_reveal_animation.dart index cbd21598e6b..a6d5b27a671 100644 --- a/packages/smooth_ui_library/lib/animations/smooth_reveal_animation.dart +++ b/packages/smooth_ui_library/lib/animations/smooth_reveal_animation.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; class SmoothRevealAnimation extends StatefulWidget { const SmoothRevealAnimation(