From 70e0620fe1083baf733a81a0c70dbb400f574e1a Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 15 Jun 2021 16:21:45 +0200 Subject: [PATCH] Don't make the +/- buttons part of the input field This only makes the field focused which makes the keyboard appear, which is exactly what we want to avoid when using the shortcuts --- lib/widgets/workouts/gym_mode.dart | 156 ++++++++++++++++------------- test/set_model_test.dart | 2 +- test_data/workouts.dart | 1 + 3 files changed, 86 insertions(+), 73 deletions(-) diff --git a/lib/widgets/workouts/gym_mode.dart b/lib/widgets/workouts/gym_mode.dart index 7eb08992..f214d1ad 100644 --- a/lib/widgets/workouts/gym_mode.dart +++ b/lib/widgets/workouts/gym_mode.dart @@ -274,22 +274,9 @@ class _LogPageState extends State { } Widget getRepsWidget() { - return TextFormField( - decoration: InputDecoration( - labelText: AppLocalizations.of(context).repetitions, - suffixIcon: IconButton( - icon: Icon( - Icons.add, - color: Colors.black, - ), - onPressed: () { - try { - int newValue = int.parse(_repsController.text) + 1; - _repsController.text = newValue.toString(); - } on FormatException catch (e) {} - }, - ), - prefixIcon: IconButton( + return Row( + children: [ + IconButton( icon: Icon( Icons.remove, color: Colors.black, @@ -303,45 +290,48 @@ class _LogPageState extends State { } on FormatException catch (e) {} }, ), - ), - enabled: true, - controller: _repsController, - keyboardType: TextInputType.number, - onFieldSubmitted: (_) {}, - onSaved: (newValue) { - widget._log.reps = int.parse(newValue!); - }, - validator: (value) { - try { - int.parse(value!); - } catch (error) { - return AppLocalizations.of(context).enterValidNumber; - } - return null; - }, - ); - } - - Widget getWeightWidget() { - return TextFormField( - decoration: InputDecoration( - labelText: AppLocalizations.of(context).weight, - suffixIcon: IconButton( + Expanded( + child: TextFormField( + decoration: InputDecoration( + labelText: AppLocalizations.of(context).repetitions, + ), + enabled: true, + controller: _repsController, + keyboardType: TextInputType.number, + onFieldSubmitted: (_) {}, + onSaved: (newValue) { + widget._log.reps = int.parse(newValue!); + }, + validator: (value) { + try { + int.parse(value!); + } catch (error) { + return AppLocalizations.of(context).enterValidNumber; + } + return null; + }, + ), + ), + IconButton( icon: Icon( Icons.add, color: Colors.black, ), onPressed: () { try { - double newValue = double.parse(_weightController.text) + 1.25; - setState(() { - widget._log.weight = newValue; - _weightController.text = newValue.toString(); - }); + int newValue = int.parse(_repsController.text) + 1; + _repsController.text = newValue.toString(); } on FormatException catch (e) {} }, ), - prefixIcon: IconButton( + ], + ); + } + + Widget getWeightWidget() { + return Row( + children: [ + IconButton( icon: Icon( Icons.remove, color: Colors.black, @@ -358,31 +348,53 @@ class _LogPageState extends State { } on FormatException catch (e) {} }, ), - ), - controller: _weightController, - keyboardType: TextInputType.number, - onFieldSubmitted: (_) {}, - onChanged: (value) { - try { - double.parse(value); - setState(() { - widget._log.weight = double.parse(value); - }); - } on FormatException catch (e) {} - }, - onSaved: (newValue) { - setState(() { - widget._log.weight = double.parse(newValue!); - }); - }, - validator: (value) { - try { - double.parse(value!); - } catch (error) { - return AppLocalizations.of(context).enterValidNumber; - } - return null; - }, + Expanded( + child: TextFormField( + decoration: InputDecoration( + labelText: AppLocalizations.of(context).weight, + ), + controller: _weightController, + keyboardType: TextInputType.number, + onFieldSubmitted: (_) {}, + onChanged: (value) { + try { + double.parse(value); + setState(() { + widget._log.weight = double.parse(value); + }); + } on FormatException catch (e) {} + }, + onSaved: (newValue) { + setState(() { + widget._log.weight = double.parse(newValue!); + }); + }, + validator: (value) { + try { + double.parse(value!); + } catch (error) { + return AppLocalizations.of(context).enterValidNumber; + } + return null; + }, + ), + ), + IconButton( + icon: Icon( + Icons.add, + color: Colors.black, + ), + onPressed: () { + try { + double newValue = double.parse(_weightController.text) + 1.25; + setState(() { + widget._log.weight = newValue; + _weightController.text = newValue.toString(); + }); + } on FormatException catch (e) {} + }, + ), + ], ); } @@ -518,7 +530,7 @@ class _LogPageState extends State { style: Theme.of(context).textTheme.headline6, ), SizedBox( - height: 40, + height: 35, child: plates.length > 0 ? Row( mainAxisSize: MainAxisSize.max, diff --git a/test/set_model_test.dart b/test/set_model_test.dart index 183a1240..60f1bdae 100644 --- a/test/set_model_test.dart +++ b/test/set_model_test.dart @@ -27,7 +27,7 @@ void main() { final set = workout.days.first.sets.first; final exercise1 = set.exercisesObj[0]; - expect(set.getSmartTextRepr(exercise1), '2 Repetitions (2 RiR)'); + expect(set.getSmartTextRepr(exercise1), '2 × 10 kg (2 RiR)'); }); }); } diff --git a/test_data/workouts.dart b/test_data/workouts.dart index a6ee3563..1f25abf8 100644 --- a/test_data/workouts.dart +++ b/test_data/workouts.dart @@ -46,6 +46,7 @@ WorkoutPlan getWorkout() { setting1.repetitionUnit = repetitionUnit1; setting1.weightUnit = weightUnit1; setting1.exercise = exercise1; + setting1.weight = 10; var log1 = Log.empty() ..id = 1