-
-
Notifications
You must be signed in to change notification settings - Fork 287
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: #833 - dev mode #834
Changes from 4 commits
66a4f82
a6ed5fe
f1eb63f
f4de890
fe57921
764df2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<void> 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)); | ||
|
||
set devMode(final int value) => | ||
_sharedPreferences.setInt(_TAG_DEV_MODE, value); | ||
|
||
int get devMode => _sharedPreferences.getInt(_TAG_DEV_MODE) ?? 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not a bool instead There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course a |
||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,7 +1,9 @@ | ||||
import 'package:flutter/cupertino.dart'; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
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 +16,8 @@ class ForgotPasswordPage extends StatefulWidget { | |||
} | ||||
|
||||
class _ForgotPasswordPageState extends State<ForgotPasswordPage> { | ||||
int _devModeCounter = 0; | ||||
|
||||
static Color _textFieldBackgroundColor = const Color.fromARGB( | ||||
255, | ||||
240, | ||||
|
@@ -65,6 +69,7 @@ class _ForgotPasswordPageState extends State<ForgotPasswordPage> { | |||
final ThemeData theme = Theme.of(context); | ||||
final ThemeProvider themeProvider = context.watch<ThemeProvider>(); | ||||
final AppLocalizations appLocalizations = AppLocalizations.of(context)!; | ||||
final UserPreferences userPreferences = context.watch<UserPreferences>(); | ||||
final Size size = MediaQuery.of(context).size; | ||||
|
||||
// Needs to be changed | ||||
|
@@ -136,6 +141,30 @@ class _ForgotPasswordPageState extends State<ForgotPasswordPage> { | |||
], | ||||
validator: (String? value) { | ||||
if (value == null || value.isEmpty) { | ||||
_devModeCounter++; | ||||
if (_devModeCounter >= 10) { | ||||
if (userPreferences.devMode == 0) { | ||||
showDialog<void>( | ||||
context: context, | ||||
builder: (BuildContext context) => AlertDialog( | ||||
title: const Text('Ready for the dev mode?'), | ||||
actions: <Widget>[ | ||||
TextButton( | ||||
child: Text(appLocalizations.yes), | ||||
onPressed: () { | ||||
userPreferences.devMode = 1; | ||||
Navigator.pop(context); | ||||
}, | ||||
), | ||||
TextButton( | ||||
child: Text(appLocalizations.no), | ||||
onPressed: () => Navigator.pop(context), | ||||
) | ||||
], | ||||
), | ||||
); | ||||
} | ||||
} | ||||
return appLocalizations.enter_some_text; | ||||
} | ||||
return null; | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Widget> getBody() => <Widget>[ | ||
ListTile( | ||
title: const Text('Remove dev mode'), | ||
onTap: () async { | ||
userPreferences.devMode = 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(() {}); | ||
}, | ||
), | ||
]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency please either all get/set or all methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Too bad the dart setter syntax does not work with
async
.