-
-
Notifications
You must be signed in to change notification settings - Fork 429
Feature/add server validation comments #959
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
40d9261
8b602fe
087c123
cc1c6cb
1e563f3
b3a5e15
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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # | ||
| # Generated file, do not edit. | ||
| # | ||
|
|
||
| import lldb | ||
|
|
||
| def handle_new_rx_page(frame: lldb.SBFrame, bp_loc, extra_args, intern_dict): | ||
| """Intercept NOTIFY_DEBUGGER_ABOUT_RX_PAGES and touch the pages.""" | ||
| base = frame.register["x0"].GetValueAsAddress() | ||
| page_len = frame.register["x1"].GetValueAsUnsigned() | ||
|
|
||
| # Note: NOTIFY_DEBUGGER_ABOUT_RX_PAGES will check contents of the | ||
| # first page to see if handled it correctly. This makes diagnosing | ||
| # misconfiguration (e.g. missing breakpoint) easier. | ||
| data = bytearray(page_len) | ||
| data[0:8] = b'IHELPED!' | ||
|
|
||
| error = lldb.SBError() | ||
| frame.GetThread().GetProcess().WriteMemory(base, data, error) | ||
| if not error.Success(): | ||
| print(f'Failed to write into {base}[+{page_len}]', error) | ||
| return | ||
|
|
||
| def __lldb_init_module(debugger: lldb.SBDebugger, _): | ||
| target = debugger.GetDummyTarget() | ||
| # Caveat: must use BreakpointCreateByRegEx here and not | ||
| # BreakpointCreateByName. For some reasons callback function does not | ||
| # get carried over from dummy target for the later. | ||
| bp = target.BreakpointCreateByRegex("^NOTIFY_DEBUGGER_ABOUT_RX_PAGES$") | ||
| bp.SetScriptCallbackFunction('{}.handle_new_rx_page'.format(__name__)) | ||
| bp.SetAutoContinue(True) | ||
| print("-- LLDB integration loaded --") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # | ||
| # Generated file, do not edit. | ||
| # | ||
|
|
||
| command script import --relative-to-command-file flutter_lldb_helper.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,8 @@ import 'package:wger/providers/user.dart'; | |
| import 'package:wger/screens/exercise_screen.dart'; | ||
| import 'package:wger/widgets/add_exercise/steps/step_1_basics.dart'; | ||
| import 'package:wger/widgets/add_exercise/steps/step_2_variations.dart'; | ||
| import 'package:wger/widgets/add_exercise/steps/step_3_description.dart'; | ||
| import 'package:wger/widgets/add_exercise/steps/step_4_translations.dart'; | ||
| import 'package:wger/widgets/add_exercise/steps/step_3_description.dart' as step3; | ||
| import 'package:wger/widgets/add_exercise/steps/step_4_translations.dart' as step4; | ||
| import 'package:wger/widgets/add_exercise/steps/step_5_images.dart'; | ||
| import 'package:wger/widgets/add_exercise/steps/step_6_overview.dart'; | ||
| import 'package:wger/widgets/core/app_bar.dart'; | ||
|
|
@@ -46,7 +46,9 @@ class _AddExerciseStepperState extends State<AddExerciseStepper> { | |
| int _currentStep = 0; | ||
| int lastStepIndex = AddExerciseStepper.STEPS_IN_FORM - 1; | ||
| bool _isLoading = false; | ||
| bool _isValidating = false; | ||
| Widget errorWidget = const SizedBox.shrink(); | ||
| String? _validationError; | ||
|
Member
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. you can take a look at
Author
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. Now using |
||
|
|
||
| final List<GlobalKey<FormState>> _keys = [ | ||
| GlobalKey<FormState>(), | ||
|
|
@@ -57,16 +59,67 @@ class _AddExerciseStepperState extends State<AddExerciseStepper> { | |
| GlobalKey<FormState>(), | ||
| ]; | ||
|
|
||
| Future<bool> _validateLanguageOnServer(BuildContext context) async { | ||
|
Member
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. I had hoped we could add something to the fields themselves so that the logic would be directly in e.g. Step3Description or AddExerciseTextArea. I find it very baffling that flutter does not have support for async validators, then this would be way easier |
||
| final addExerciseProvider = context.read<AddExerciseProvider>(); | ||
|
|
||
| try { | ||
| if (_currentStep == 2) { | ||
| await addExerciseProvider.validateLanguage( | ||
| addExerciseProvider.descriptionEn ?? '', | ||
| 'en', | ||
| ); | ||
| } | ||
|
|
||
| if (_currentStep == 3 && addExerciseProvider.descriptionTrans != null) { | ||
| final languageCode = addExerciseProvider.languageTranslation?.shortName ?? ''; | ||
| if (languageCode.isNotEmpty) { | ||
| await addExerciseProvider.validateLanguage( | ||
| addExerciseProvider.descriptionTrans ?? '', | ||
| languageCode, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } on WgerHttpException catch (error) { | ||
| if (mounted) { | ||
| setState(() { | ||
| _validationError = error.toString(); | ||
| }); | ||
| } | ||
| return false; | ||
| } catch (error) { | ||
| if (mounted) { | ||
| setState(() { | ||
| _validationError = error.toString(); | ||
| }); | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| Widget _controlsBuilder(BuildContext context, ControlsDetails details) { | ||
| return Column( | ||
| children: [ | ||
| const SizedBox(height: 10), | ||
|
|
||
| if (_validationError != null && _currentStep != lastStepIndex) | ||
| Padding( | ||
| padding: const EdgeInsets.symmetric(vertical: 8.0), | ||
| child: Text( | ||
| _validationError!, | ||
| style: TextStyle(color: Theme.of(context).colorScheme.error), | ||
| textAlign: TextAlign.center, | ||
| ), | ||
| ), | ||
|
|
||
| if (_currentStep == lastStepIndex) errorWidget, | ||
|
|
||
| Row( | ||
| mainAxisAlignment: MainAxisAlignment.spaceAround, | ||
| children: [ | ||
| OutlinedButton( | ||
| onPressed: details.onStepCancel, | ||
| onPressed: _isValidating ? null : details.onStepCancel, | ||
| child: Text(AppLocalizations.of(context).previous), | ||
| ), | ||
|
|
||
|
|
@@ -76,70 +129,112 @@ class _AddExerciseStepperState extends State<AddExerciseStepper> { | |
| onPressed: _isLoading | ||
| ? null | ||
| : () async { | ||
| setState(() { | ||
| _isLoading = true; | ||
| errorWidget = const SizedBox.shrink(); | ||
| }); | ||
| final addExerciseProvider = context.read<AddExerciseProvider>(); | ||
| final exerciseProvider = context.read<ExercisesProvider>(); | ||
|
|
||
| Exercise? exercise; | ||
| try { | ||
| final exerciseId = await addExerciseProvider.postExerciseToServer(); | ||
| exercise = await exerciseProvider.fetchAndSetExercise(exerciseId); | ||
| } on WgerHttpException catch (error) { | ||
| if (context.mounted) { | ||
| setState(() { | ||
| errorWidget = FormHttpErrorsWidget(error); | ||
| }); | ||
| } | ||
| } finally { | ||
| if (mounted) { | ||
| setState(() { | ||
| _isLoading = false; | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| if (exercise == null || !context.mounted) { | ||
| return; | ||
| } | ||
|
|
||
| final name = exercise | ||
| .getTranslation(Localizations.localeOf(context).languageCode) | ||
| .name; | ||
|
|
||
| return showDialog( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return AlertDialog( | ||
| title: Text(AppLocalizations.of(context).success), | ||
| content: Text(AppLocalizations.of(context).cacheWarning), | ||
| actions: [ | ||
| TextButton( | ||
| child: Text(name), | ||
| onPressed: () { | ||
| Navigator.of(context).pop(); | ||
| Navigator.pushReplacementNamed( | ||
| context, | ||
| ExerciseDetailScreen.routeName, | ||
| arguments: exercise, | ||
| ); | ||
| }, | ||
| ), | ||
| ], | ||
| ); | ||
| }, | ||
| ); | ||
| }, | ||
| setState(() { | ||
| _isLoading = true; | ||
| errorWidget = const SizedBox.shrink(); | ||
| }); | ||
| final addExerciseProvider = context.read<AddExerciseProvider>(); | ||
| final exerciseProvider = context.read<ExercisesProvider>(); | ||
|
|
||
| Exercise? exercise; | ||
| try { | ||
| final exerciseId = await addExerciseProvider.postExerciseToServer(); | ||
| exercise = await exerciseProvider.fetchAndSetExercise(exerciseId); | ||
| } on WgerHttpException catch (error) { | ||
| if (context.mounted) { | ||
| setState(() { | ||
| errorWidget = FormHttpErrorsWidget(error); | ||
| }); | ||
| } | ||
| } finally { | ||
| if (mounted) { | ||
| setState(() { | ||
| _isLoading = false; | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| if (exercise == null || !context.mounted) { | ||
| return; | ||
| } | ||
|
|
||
| final name = exercise | ||
| .getTranslation(Localizations.localeOf(context).languageCode) | ||
| .name; | ||
|
|
||
| return showDialog( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return AlertDialog( | ||
| title: Text(AppLocalizations.of(context).success), | ||
| content: Text(AppLocalizations.of(context).cacheWarning), | ||
| actions: [ | ||
| TextButton( | ||
| child: Text(name), | ||
| onPressed: () { | ||
| Navigator.of(context).pop(); | ||
| Navigator.pushReplacementNamed( | ||
| context, | ||
| ExerciseDetailScreen.routeName, | ||
| arguments: exercise, | ||
| ); | ||
| }, | ||
| ), | ||
| ], | ||
| ); | ||
| }, | ||
| ); | ||
| }, | ||
| child: _isLoading | ||
| ? const SizedBox(height: 20, width: 20, child: CircularProgressIndicator()) | ||
| : Text(AppLocalizations.of(context).save), | ||
| ) | ||
| else | ||
| ElevatedButton( | ||
| onPressed: details.onStepContinue, | ||
| child: Text(AppLocalizations.of(context).next), | ||
| onPressed: _isValidating | ||
| ? null | ||
| : () async { | ||
| setState(() { | ||
| _validationError = null; | ||
| }); | ||
|
|
||
| if (!(_keys[_currentStep].currentState?.validate() ?? false)) { | ||
| return; | ||
| } | ||
|
|
||
| _keys[_currentStep].currentState?.save(); | ||
|
|
||
| if (_currentStep == 2 || _currentStep == 3) { | ||
| setState(() { | ||
| _isValidating = true; | ||
| }); | ||
|
|
||
| final isValid = await _validateLanguageOnServer(context); | ||
|
|
||
| if (mounted) { | ||
| setState(() { | ||
| _isValidating = false; | ||
| }); | ||
| } | ||
|
|
||
| if (!isValid) { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| if (_currentStep != lastStepIndex) { | ||
| setState(() { | ||
| _currentStep += 1; | ||
| }); | ||
| } | ||
| }, | ||
| child: _isValidating | ||
| ? const SizedBox( | ||
| height: 20, | ||
| width: 20, | ||
| child: CircularProgressIndicator(strokeWidth: 2), | ||
| ) | ||
| : Text(AppLocalizations.of(context).next), | ||
| ), | ||
| ], | ||
| ), | ||
|
|
@@ -164,42 +259,29 @@ class _AddExerciseStepperState extends State<AddExerciseStepper> { | |
| ), | ||
| Step( | ||
| title: Text(AppLocalizations.of(context).description), | ||
| content: Step3Description(formkey: _keys[2]), | ||
| content: step3.Step3Description(formkey: _keys[2]), | ||
| ), | ||
| Step( | ||
| title: Text(AppLocalizations.of(context).translation), | ||
| content: Step4Translation(formkey: _keys[3]), | ||
| content: step4.Step4Translation(formkey: _keys[3]), | ||
| ), | ||
| Step( | ||
| title: Text(AppLocalizations.of(context).images), | ||
| content: Step5Images(formkey: _keys[4]), | ||
| ), | ||
| Step(title: Text(AppLocalizations.of(context).overview), content: Step6Overview()), | ||
| Step( | ||
| title: Text(AppLocalizations.of(context).overview), | ||
| content: Step6Overview(), | ||
| ), | ||
| ], | ||
| currentStep: _currentStep, | ||
| onStepContinue: () { | ||
| if (_keys[_currentStep].currentState?.validate() ?? false) { | ||
| _keys[_currentStep].currentState?.save(); | ||
|
|
||
| if (_currentStep != lastStepIndex) { | ||
| setState(() { | ||
| _currentStep += 1; | ||
| }); | ||
| } | ||
| } | ||
| }, | ||
| onStepContinue: null, // Použijeme vlastnú logiku v _controlsBuilder | ||
| onStepCancel: () => setState(() { | ||
| if (_currentStep != 0) { | ||
| _currentStep -= 1; | ||
| _validationError = null; // Resetovať chybu pri návrate | ||
| } | ||
| }), | ||
| /* | ||
| onStepTapped: (int index) { | ||
| setState(() { | ||
| _currentStep = index; | ||
| }); | ||
| }, | ||
| */ | ||
| ), | ||
| ); | ||
| } | ||
|
|
@@ -256,4 +338,4 @@ class EmailNotVerified extends StatelessWidget { | |
| ), | ||
| ); | ||
| } | ||
| } | ||
| } | ||
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.
I was really confused about this till I saw that it's one of flutter's generated files 😅