From 40164e242a4a73733281bc4f69200524060426b9 Mon Sep 17 00:00:00 2001 From: Marcin Federowicz Date: Sat, 1 Oct 2022 22:13:16 +0200 Subject: [PATCH] refactor: avoid_unnecessary_containers linter rule --- lib/UI/exercise/add_exercise_widget.dart | 28 +++---- lib/UI/exercise/exercise_card.dart | 44 +++++------ lib/UI/prev_workout/prev_exercise_card.dart | 26 +++--- lib/UI/prev_workout/prev_workout_page.dart | 9 +-- lib/UI/workout/save_workout_dialog.dart | 42 +++++----- lib/UI/workout/workout_toatals_widget.dart | 88 ++++++++------------- test/widget_test.dart | 4 +- 7 files changed, 101 insertions(+), 140 deletions(-) diff --git a/lib/UI/exercise/add_exercise_widget.dart b/lib/UI/exercise/add_exercise_widget.dart index e26c027..b1d156b 100644 --- a/lib/UI/exercise/add_exercise_widget.dart +++ b/lib/UI/exercise/add_exercise_widget.dart @@ -56,21 +56,19 @@ class _ExerciseNameSelectionWidgetState extends State( - optionsMaxHeight: 100, - onSelected: (value) { - widget.setExercisename(value); - }, - optionsBuilder: (TextEditingValue textEditingValue) { - widget.setExercisename(textEditingValue.text); - return snapshot.data!.where( - (String name) => name.toLowerCase().startsWith( - textEditingValue.text.toLowerCase(), - ), - ); - }, - ), + child: Autocomplete( + optionsMaxHeight: 100, + onSelected: (value) { + widget.setExercisename(value); + }, + optionsBuilder: (TextEditingValue textEditingValue) { + widget.setExercisename(textEditingValue.text); + return snapshot.data!.where( + (String name) => name.toLowerCase().startsWith( + textEditingValue.text.toLowerCase(), + ), + ); + }, ), ), ); diff --git a/lib/UI/exercise/exercise_card.dart b/lib/UI/exercise/exercise_card.dart index a31194a..8c59373 100644 --- a/lib/UI/exercise/exercise_card.dart +++ b/lib/UI/exercise/exercise_card.dart @@ -121,31 +121,27 @@ class _ExerciseCardState extends State with AutomaticKeepAliveClie height: height, child: Column( children: [ - Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Container( - height: getHeight(), - width: screenWidth * 0.45, - child: Text( - widget.name, - style: mediumTitleStyleWhite, - ), - ), - Container( - child: ValueListenableBuilder( - valueListenable: _notifier, - builder: (BuildContext context, TotalsData value, Widget? child) { - return ExerciseTotalsWidget( - totals: value, - index: index, - ); - }, - ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Container( + height: getHeight(), + width: screenWidth * 0.45, + child: Text( + widget.name, + style: mediumTitleStyleWhite, ), - ], - ), + ), + ValueListenableBuilder( + valueListenable: _notifier, + builder: (BuildContext context, TotalsData value, Widget? child) { + return ExerciseTotalsWidget( + totals: value, + index: index, + ); + }, + ), + ], ), Divider( thickness: 1, diff --git a/lib/UI/prev_workout/prev_exercise_card.dart b/lib/UI/prev_workout/prev_exercise_card.dart index 3e1c0c1..7a01dee 100644 --- a/lib/UI/prev_workout/prev_exercise_card.dart +++ b/lib/UI/prev_workout/prev_exercise_card.dart @@ -85,21 +85,19 @@ class _PrevExerciseCardState extends State with AutomaticKeepA height: height, child: Column( children: [ - Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Container( - height: getHeight(), - width: screenWidth * 0.45, - child: Text( - widget.name, - style: mediumTitleStyleWhite, - ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Container( + height: getHeight(), + width: screenWidth * 0.45, + child: Text( + widget.name, + style: mediumTitleStyleWhite, ), - totalWidget - ], - ), + ), + totalWidget + ], ), Divider( thickness: 1, diff --git a/lib/UI/prev_workout/prev_workout_page.dart b/lib/UI/prev_workout/prev_workout_page.dart index 560996b..60d6cd8 100644 --- a/lib/UI/prev_workout/prev_workout_page.dart +++ b/lib/UI/prev_workout/prev_workout_page.dart @@ -108,12 +108,9 @@ class _PrevWorkoutPageState extends State { totals: workoutData.totals, ), Expanded( - child: Container( - //height: screenHeight * 0.5, - child: ListView( - addAutomaticKeepAlives: true, - children: workoutData.exerciseWidgets, - ), + child: ListView( + addAutomaticKeepAlives: true, + children: workoutData.exerciseWidgets, ), ), ], diff --git a/lib/UI/workout/save_workout_dialog.dart b/lib/UI/workout/save_workout_dialog.dart index 4f3354e..d6f6525 100644 --- a/lib/UI/workout/save_workout_dialog.dart +++ b/lib/UI/workout/save_workout_dialog.dart @@ -75,29 +75,25 @@ class _SaveWorkoutAlertState extends State { ), ), ), - Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Container( - child: Text( - 'Save as template', - style: mediumTitleStyleWhite, - ), - ), - Checkbox( - fillColor: MaterialStateProperty.all(theme.colorTheme.primaryColor), - value: this.template, - onChanged: (bool? value) { - setState(() { - Log.info(value.toString()); - template = value; - widget.setWorkout(name, template!); - }); - }, - ), - ], - ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Save as template', + style: mediumTitleStyleWhite, + ), + Checkbox( + fillColor: MaterialStateProperty.all(theme.colorTheme.primaryColor), + value: this.template, + onChanged: (bool? value) { + setState(() { + Log.info(value.toString()); + template = value; + widget.setWorkout(name, template!); + }); + }, + ), + ], ), Container( height: screenHeight * 0.05, diff --git a/lib/UI/workout/workout_toatals_widget.dart b/lib/UI/workout/workout_toatals_widget.dart index 2cfee5d..e3d62ba 100644 --- a/lib/UI/workout/workout_toatals_widget.dart +++ b/lib/UI/workout/workout_toatals_widget.dart @@ -32,11 +32,9 @@ class _WorkoutTotalsWidgetState extends State { children: [ Row( children: [ - Container( - child: Text( - 'Totals', - style: mediumTitleStyleWhite, - ), + Text( + 'Totals', + style: mediumTitleStyleWhite, ) ], ), @@ -48,81 +46,61 @@ class _WorkoutTotalsWidgetState extends State { children: [ Column( children: [ - Container( - child: Text( - 'sets', - style: setStyle, - ), + Text( + 'sets', + style: setStyle, ), - Container( - child: Text( - widget.totals.sets.toString(), - style: setStyle, - ), + Text( + widget.totals.sets.toString(), + style: setStyle, ) ], ), Column( children: [ - Container( - child: Text( - 'reps', - style: setStyle, - ), + Text( + 'reps', + style: setStyle, ), - Container( - child: Text( - widget.totals.reps.toString(), - style: setStyle, - ), + Text( + widget.totals.reps.toString(), + style: setStyle, ) ], ), Column( children: [ - Container( - child: Text( - 'load', - style: setStyle, - ), + Text( + 'load', + style: setStyle, ), - Container( - child: Text( - widget.totals.weight.toString(), - style: setStyle, - ), + Text( + widget.totals.weight.toString(), + style: setStyle, ) ], ), Column( children: [ - Container( - child: Text( - 'kg/rep', - style: setStyle, - ), + Text( + 'kg/rep', + style: setStyle, ), - Container( - child: Text( - widget.totals.avgKgs.toString(), - style: setStyle, - ), + Text( + widget.totals.avgKgs.toString(), + style: setStyle, ) ], ), Column( children: [ - Container( - child: Text( - 'exercises', - style: setStyle, - ), + Text( + 'exercises', + style: setStyle, ), - Container( - child: Text( - widget.totals.exercises.toString(), - style: setStyle, - ), + Text( + widget.totals.exercises.toString(), + style: setStyle, ) ], ), diff --git a/test/widget_test.dart b/test/widget_test.dart index 040be02..b762bd0 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -10,9 +10,7 @@ void main() { await tester.runAsync(() async { await tester.pumpWidget(MaterialApp( title: 'EXERLOG', - home: Container( - child: const Text('EXERLOG'), - ), + home: const Text('EXERLOG'), ),); }); }