@@ -270,6 +270,7 @@ class SetFormWidget extends StatefulWidget {
270
270
class _SetFormWidgetState extends State <SetFormWidget > {
271
271
double _currentSetSliderValue = Set .DEFAULT_NR_SETS .toDouble ();
272
272
bool _detailed = false ;
273
+ bool _searchEnglish = true ;
273
274
274
275
// Form stuff
275
276
final GlobalKey <FormState > _formKey = GlobalKey ();
@@ -292,6 +293,8 @@ class _SetFormWidgetState extends State<SetFormWidget> {
292
293
293
294
/// Adds settings to the set
294
295
void addSettings () {
296
+ final workoutProvider = context.read <WorkoutPlansProvider >();
297
+
295
298
widget._set.settings = [];
296
299
int order = 0 ;
297
300
for (final exercise in widget._set.exerciseBasesObj) {
@@ -300,10 +303,8 @@ class _SetFormWidgetState extends State<SetFormWidget> {
300
303
final Setting setting = Setting .empty ();
301
304
setting.order = order;
302
305
setting.exerciseBase = exercise;
303
- setting.weightUnit =
304
- Provider .of <WorkoutPlansProvider >(context, listen: false ).defaultWeightUnit;
305
- setting.repetitionUnit =
306
- Provider .of <WorkoutPlansProvider >(context, listen: false ).defaultRepetitionUnit;
306
+ setting.weightUnit = workoutProvider.defaultWeightUnit;
307
+ setting.repetitionUnit = workoutProvider.defaultRepetitionUnit;
307
308
308
309
widget._set.settings.add (setting);
309
310
}
@@ -355,84 +356,104 @@ class _SetFormWidgetState extends State<SetFormWidget> {
355
356
child: Column (
356
357
children: [
357
358
Card (
358
- child: TypeAheadFormField <ExerciseBase >(
359
- key: const Key ('field-typeahead' ),
360
- textFieldConfiguration: TextFieldConfiguration (
361
- controller: _exercisesController,
362
- decoration: InputDecoration (
363
- labelText: AppLocalizations .of (context).searchExercise,
364
- prefixIcon: const Icon (Icons .search),
365
- suffixIcon: IconButton (
366
- icon: const Icon (Icons .help),
367
- onPressed: () {
368
- showDialog (
369
- context: context,
370
- builder: (context) => AlertDialog (
371
- content: Column (
372
- mainAxisSize: MainAxisSize .min,
373
- children: [
374
- Text (AppLocalizations .of (context).selectExercises),
375
- const SizedBox (height: 10 ),
376
- Text (AppLocalizations .of (context).sameRepetitions)
377
- ],
378
- ),
379
- actions: [
380
- TextButton (
381
- child: Text (MaterialLocalizations .of (context).closeButtonLabel),
382
- onPressed: () {
383
- Navigator .of (context).pop ();
384
- },
359
+ child: Column (
360
+ children: [
361
+ TypeAheadFormField <ExerciseBase >(
362
+ key: const Key ('field-typeahead' ),
363
+ textFieldConfiguration: TextFieldConfiguration (
364
+ controller: _exercisesController,
365
+ decoration: InputDecoration (
366
+ labelText: AppLocalizations .of (context).searchExercise,
367
+ prefixIcon: const Icon (Icons .search),
368
+ suffixIcon: IconButton (
369
+ icon: const Icon (Icons .help),
370
+ onPressed: () {
371
+ showDialog (
372
+ context: context,
373
+ builder: (context) => AlertDialog (
374
+ content: Column (
375
+ mainAxisSize: MainAxisSize .min,
376
+ children: [
377
+ Text (AppLocalizations .of (context).selectExercises),
378
+ const SizedBox (height: 10 ),
379
+ Text (AppLocalizations .of (context).sameRepetitions)
380
+ ],
381
+ ),
382
+ actions: [
383
+ TextButton (
384
+ child: Text (
385
+ MaterialLocalizations .of (context).closeButtonLabel),
386
+ onPressed: () {
387
+ Navigator .of (context).pop ();
388
+ },
389
+ ),
390
+ ],
385
391
),
386
- ],
387
- ),
388
- );
389
- },
392
+ );
393
+ },
394
+ ),
395
+ errorMaxLines: 2 ,
396
+ border: InputBorder .none,
397
+ ),
390
398
),
391
- errorMaxLines: 2 ,
399
+ suggestionsCallback: (pattern) {
400
+ return context.read <ExercisesProvider >().searchExercise (
401
+ pattern,
402
+ languageCode: Localizations .localeOf (context).languageCode,
403
+ searchEnglish: _searchEnglish,
404
+ );
405
+ },
406
+ itemBuilder: (BuildContext context, ExerciseBase exerciseSuggestion) {
407
+ return ListTile (
408
+ leading: SizedBox (
409
+ width: 45 ,
410
+ child: ExerciseImageWidget (image: exerciseSuggestion.getMainImage),
411
+ ),
412
+ title: Text (
413
+ exerciseSuggestion
414
+ .getExercise (Localizations .localeOf (context).languageCode)
415
+ .name,
416
+ ),
417
+ subtitle: Text (
418
+ '${exerciseSuggestion .category .name } / ${exerciseSuggestion .equipment .map ((e ) => e .name ).join (', ' )}' ,
419
+ ),
420
+ );
421
+ },
422
+ transitionBuilder: (context, suggestionsBox, controller) {
423
+ return suggestionsBox;
424
+ },
425
+ onSuggestionSelected: (ExerciseBase exerciseSuggestion) {
426
+ addExercise (exerciseSuggestion);
427
+ this ._exercisesController.text = '' ;
428
+ },
429
+ validator: (value) {
430
+ // At least one exercise must be selected
431
+ if (widget._set.exerciseBasesIds.isEmpty) {
432
+ return AppLocalizations .of (context).selectExercise;
433
+ }
434
+
435
+ // At least one setting has to be filled in
436
+ if (widget._set.settings
437
+ .where ((s) => s.weight == null && s.reps == null )
438
+ .length ==
439
+ widget._set.settings.length) {
440
+ return AppLocalizations .of (context).enterRepetitionsOrWeight;
441
+ }
442
+ return null ;
443
+ },
392
444
),
393
- ),
394
- suggestionsCallback: (pattern) {
395
- return Provider .of <ExercisesProvider >(context, listen: false ).searchExercise (
396
- pattern,
397
- Localizations .localeOf (context).languageCode,
398
- );
399
- },
400
- itemBuilder: (BuildContext context, ExerciseBase exerciseSuggestion) {
401
- return ListTile (
402
- leading: SizedBox (
403
- width: 45 ,
404
- child: ExerciseImageWidget (image: exerciseSuggestion.getMainImage),
405
- ),
406
- title: Text (exerciseSuggestion
407
- .getExercise (Localizations .localeOf (context).languageCode)
408
- .name),
409
- subtitle: Text (
410
- '${exerciseSuggestion .category .name } / ${exerciseSuggestion .equipment .map ((e ) => e .name ).join (', ' )}' ,
411
- ),
412
- );
413
- },
414
- transitionBuilder: (context, suggestionsBox, controller) {
415
- return suggestionsBox;
416
- },
417
- onSuggestionSelected: (ExerciseBase exerciseSuggestion) {
418
- addExercise (exerciseSuggestion);
419
- this ._exercisesController.text = '' ;
420
- },
421
- validator: (value) {
422
- // At least one exercise must be selected
423
- if (widget._set.exerciseBasesIds.isEmpty) {
424
- return AppLocalizations .of (context).selectExercise;
425
- }
426
-
427
- // At least one setting has to be filled in
428
- if (widget._set.settings
429
- .where ((s) => s.weight == null && s.reps == null )
430
- .length ==
431
- widget._set.settings.length) {
432
- return AppLocalizations .of (context).enterRepetitionsOrWeight;
433
- }
434
- return null ;
435
- },
445
+ if (Localizations .localeOf (context).languageCode != LANGUAGE_SHORT_ENGLISH )
446
+ SwitchListTile (
447
+ title: Text (AppLocalizations .of (context).searchNamesInEnglish),
448
+ value: _searchEnglish,
449
+ onChanged: (_) {
450
+ setState (() {
451
+ _searchEnglish = ! _searchEnglish;
452
+ });
453
+ },
454
+ dense: true ,
455
+ )
456
+ ],
436
457
),
437
458
),
438
459
const SizedBox (height: 10 ),
@@ -859,6 +880,7 @@ class _WeightUnitInputWidgetState extends State<WeightUnitInputWidget> {
859
880
/// Can be used with a Setting or a Log object
860
881
class RepetitionUnitInputWidget extends StatefulWidget {
861
882
final dynamic _setting;
883
+
862
884
const RepetitionUnitInputWidget (this ._setting);
863
885
864
886
@override
0 commit comments