Skip to content

Commit

Permalink
Children at the bottom + consistent variable names + BuildContext asy…
Browse files Browse the repository at this point in the history
…nc gaps
  • Loading branch information
Miroslav Mazel committed Nov 5, 2023
1 parent 15923ae commit d86ee69
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 100 deletions.
2 changes: 1 addition & 1 deletion lib/widgets/add_exercise/add_exercise_dropdown_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class _AddExerciseDropdownButtonState extends State<AddExerciseDropdownButton> {
items: widget.items
.map(
(item) => DropdownMenuItem<String>(
child: Text(item),
value: item,
child: Text(item),
),
)
.toList(),
Expand Down
19 changes: 12 additions & 7 deletions lib/widgets/nutrition/forms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ class MealItemForm extends StatelessWidget {
),
if (_listMealItems.isNotEmpty) const SizedBox(height: 10.0),
Container(
child: Text(AppLocalizations.of(context).recentlyUsedIngredients),
padding: const EdgeInsets.all(10.0),
child: Text(AppLocalizations.of(context).recentlyUsedIngredients),
),
Expanded(
child: ListView.builder(
Expand Down Expand Up @@ -320,8 +320,8 @@ class IngredientLogForm extends StatelessWidget {
),
if (diaryEntries.isNotEmpty) const SizedBox(height: 10.0),
Container(
child: Text(AppLocalizations.of(context).recentlyUsedIngredients),
padding: const EdgeInsets.all(10.0),
child: Text(AppLocalizations.of(context).recentlyUsedIngredients),
),
Expanded(
child: ListView.builder(
Expand Down Expand Up @@ -392,16 +392,21 @@ class PlanForm extends StatelessWidget {

// Save to DB
try {
final navigator = Navigator.of(context);
if (_plan.id != null) {
await Provider.of<NutritionPlansProvider>(context, listen: false).editPlan(_plan);
Navigator.of(context).pop();
if (context.mounted) {
navigator.pop();
}
} else {
_plan = await Provider.of<NutritionPlansProvider>(context, listen: false)
.addPlan(_plan);
Navigator.of(context).pushReplacementNamed(
NutritionalPlanScreen.routeName,
arguments: _plan,
);
if (context.mounted) {
navigator.pushReplacementNamed(
NutritionalPlanScreen.routeName,
arguments: _plan,
);
}
}

// Saving was successful, reset the data
Expand Down
62 changes: 31 additions & 31 deletions lib/widgets/nutrition/meal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,37 +223,6 @@ class DismissibleMealHeader extends StatelessWidget {
return Dismissible(
key: Key(_meal.id.toString()),
direction: DismissDirection.startToEnd,
child: Container(
padding: const EdgeInsets.all(10),
decoration: const BoxDecoration(color: Colors.white),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (_meal.name != '')
Text(
_meal.name,
style: Theme.of(context).textTheme.headline5,
),
Row(
children: [
Expanded(
child: Text(
_meal.time!.format(context),
style: Theme.of(context).textTheme.headline5,
),
),
IconButton(
visualDensity: VisualDensity.compact,
icon: _expanded ? const Icon(Icons.unfold_less) : const Icon(Icons.unfold_more),
onPressed: () {
_toggle();
},
),
],
),
],
),
),
background: Container(
color: wgerPrimaryButtonColor, //Theme.of(context).primaryColor,
alignment: Alignment.centerLeft,
Expand Down Expand Up @@ -287,6 +256,37 @@ class DismissibleMealHeader extends StatelessWidget {
}
return false;
},
child: Container(
padding: const EdgeInsets.all(10),
decoration: const BoxDecoration(color: Colors.white),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (_meal.name != '')
Text(
_meal.name,
style: Theme.of(context).textTheme.headline5,
),
Row(
children: [
Expanded(
child: Text(
_meal.time!.format(context),
style: Theme.of(context).textTheme.headline5,
),
),
IconButton(
visualDensity: VisualDensity.compact,
icon: _expanded ? const Icon(Icons.unfold_less) : const Icon(Icons.unfold_more),
onPressed: () {
_toggle();
},
),
],
),
],
),
),
);
}
}
68 changes: 34 additions & 34 deletions lib/widgets/workouts/day.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class SettingWidget extends StatelessWidget {
return ListTile(
leading: InkWell(
child: SizedBox(
child: ExerciseImageWidget(image: setting.exerciseBaseObj.getMainImage),
width: 45,
child: ExerciseImageWidget(image: setting.exerciseBaseObj.getMainImage),
),
onTap: () {
showDialog(
Expand Down Expand Up @@ -224,19 +224,19 @@ class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
buildDefaultDragHandles: false,
onReorder: (_oldIndex, _newIndex) async {
int _startIndex = 0;
if (_oldIndex < _newIndex) {
_newIndex -= 1;
_startIndex = _oldIndex;
onReorder: (oldIndex, newIndex) async {
int startIndex = 0;
if (oldIndex < newIndex) {
newIndex -= 1;
startIndex = oldIndex;
} else {
_startIndex = _newIndex;
startIndex = newIndex;
}
setState(() {
_sets.insert(_newIndex, _sets.removeAt(_oldIndex));
_sets.insert(newIndex, _sets.removeAt(oldIndex));
});
_sets = await Provider.of<WorkoutPlansProvider>(context, listen: false)
.reorderSets(_sets, _startIndex);
.reorderSets(_sets, startIndex);
},
children: [
for (var i = 0; i < widget._day.sets.length; i++) getSetRow(widget._day.sets[i], i),
Expand Down Expand Up @@ -283,6 +283,31 @@ class DayHeaderDismissible extends StatelessWidget {
return Dismissible(
key: Key(_day.id.toString()),
direction: DismissDirection.startToEnd,
background: Container(
color: wgerPrimaryButtonColor, //Theme.of(context).primaryColor,
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(left: 10),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context).gymMode,
style: const TextStyle(color: Colors.white),
),
const Icon(
Icons.play_arrow,
color: Colors.white,
),
],
),
),
confirmDismiss: (direction) async {
// Delete day
if (direction == DismissDirection.startToEnd) {
Navigator.of(context).pushNamed(GymModeScreen.routeName, arguments: _day);
}
return false;
},
child: Container(
padding: const EdgeInsets.all(10),
decoration: const BoxDecoration(color: Colors.white),
Expand Down Expand Up @@ -311,31 +336,6 @@ class DayHeaderDismissible extends StatelessWidget {
],
),
),
background: Container(
color: wgerPrimaryButtonColor, //Theme.of(context).primaryColor,
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(left: 10),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context).gymMode,
style: const TextStyle(color: Colors.white),
),
const Icon(
Icons.play_arrow,
color: Colors.white,
),
],
),
),
confirmDismiss: (direction) async {
// Delete day
if (direction == DismissDirection.startToEnd) {
Navigator.of(context).pushNamed(GymModeScreen.routeName, arguments: _day);
}
return false;
},
);
}
}
40 changes: 20 additions & 20 deletions lib/widgets/workouts/gym_mode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -466,15 +466,6 @@ class _LogPageState extends State<LogPage> {
},
),
ElevatedButton(
child: (!_isSaving)
? Text(AppLocalizations.of(context).save)
: const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
),
onPressed: _isSaving
? null
: () async {
Expand Down Expand Up @@ -512,6 +503,15 @@ class _LogPageState extends State<LogPage> {
_isSaving = false;
}
},
child: (!_isSaving)
? Text(AppLocalizations.of(context).save)
: const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
),
),
],
),
Expand Down Expand Up @@ -781,17 +781,6 @@ class _SessionPageState extends State<SessionPage> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
ToggleButtons(
children: const <Widget>[
Icon(
Icons.sentiment_very_dissatisfied,
),
Icon(
Icons.sentiment_neutral,
),
Icon(
Icons.sentiment_very_satisfied,
),
],
renderBorder: false,
onPressed: (int index) {
setState(() {
Expand All @@ -809,6 +798,17 @@ class _SessionPageState extends State<SessionPage> {
});
},
isSelected: selectedImpression,
children: const <Widget>[
Icon(
Icons.sentiment_very_dissatisfied,
),
Icon(
Icons.sentiment_neutral,
),
Icon(
Icons.sentiment_very_satisfied,
),
],
),
TextFormField(
decoration: InputDecoration(
Expand Down
14 changes: 7 additions & 7 deletions lib/widgets/workouts/workout_logs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class _WorkoutLogsState extends State<WorkoutLogs> {
return Column(
children: [
ToggleButtons(
renderBorder: false,
onPressed: (int index) {
if (index == 0) {
widget._changeMode(WorkoutScreenMode.workout);
}
},
isSelected: const [false, true],
children: const <Widget>[
Icon(
Icons.table_chart_outlined,
Expand All @@ -53,13 +60,6 @@ class _WorkoutLogsState extends State<WorkoutLogs> {
Icons.show_chart,
),
],
renderBorder: false,
onPressed: (int index) {
if (index == 0) {
widget._changeMode(WorkoutScreenMode.workout);
}
},
isSelected: const [false, true],
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
Expand Down

0 comments on commit d86ee69

Please sign in to comment.