Skip to content

Commit 814acd1

Browse files
author
Miroslav Mazel
committed
Meals + workouts: Removing Dismissible
1 parent 1983d38 commit 814acd1

10 files changed

+383
-430
lines changed

lib/l10n/app_en.arb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,5 +798,11 @@
798798
"none__bodyweight_exercise_": "none (bodyweight exercise)",
799799
"@none__bodyweight_exercise_": {
800800
"description": "Generated entry for translation for server strings"
801-
}
801+
},
802+
"editSchedule": "Edit schedule",
803+
"log": "Log",
804+
"@log": {
805+
"description": "Log a specific meal"
806+
},
807+
"done": "Done"
802808
}

lib/widgets/nutrition/meal.dart

Lines changed: 152 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,18 @@ class MealWidget extends StatefulWidget {
4343
}
4444

4545
class _MealWidgetState extends State<MealWidget> {
46-
bool _expanded = false;
46+
bool _showingDetails = false;
47+
bool _editing = false;
4748

48-
void _toggleExpanded() {
49+
void _toggleEditing() {
4950
setState(() {
50-
_expanded = !_expanded;
51+
_editing = !_editing;
52+
});
53+
}
54+
55+
void _toggleDetails() {
56+
setState(() {
57+
_showingDetails = !_showingDetails;
5158
});
5259
}
5360

@@ -57,85 +64,72 @@ class _MealWidgetState extends State<MealWidget> {
5764
padding: const EdgeInsets.all(3),
5865
child: Card(
5966
child: Column(
67+
crossAxisAlignment: CrossAxisAlignment.start,
6068
children: [
61-
DismissibleMealHeader(_expanded, _toggleExpanded, meal: widget._meal),
62-
if (_expanded)
63-
Row(
64-
mainAxisSize: MainAxisSize.max,
65-
mainAxisAlignment: MainAxisAlignment.spaceAround,
66-
children: [
67-
IconButton(
68-
onPressed: () {
69-
// Delete the meal
70-
Provider.of<NutritionPlansProvider>(context, listen: false)
71-
.deleteMeal(widget._meal);
72-
73-
// and inform the user
74-
ScaffoldMessenger.of(context).showSnackBar(
75-
SnackBar(
76-
content: Text(
77-
AppLocalizations.of(context).successfullyDeleted,
78-
textAlign: TextAlign.center,
79-
),
80-
),
81-
);
82-
},
83-
icon: const Icon(Icons.delete),
84-
),
85-
if (widget._meal.mealItems.isNotEmpty)
86-
Ink(
87-
decoration: ShapeDecoration(
88-
color: Theme.of(context).primaryColor, //wgerPrimaryButtonColor,
89-
shape: const CircleBorder(),
69+
MealHeader(
70+
editing: _editing,
71+
toggleEditing: _toggleEditing,
72+
showingDetails: _showingDetails,
73+
toggleDetails: _toggleDetails,
74+
meal: widget._meal),
75+
if (_editing)
76+
Padding(
77+
padding: const EdgeInsets.symmetric(vertical: 8),
78+
child: Wrap(
79+
spacing: 8,
80+
children: [
81+
TextButton.icon(
82+
icon: const Icon(Icons.add),
83+
label: Text(AppLocalizations.of(context).addIngredient),
84+
onPressed: () {
85+
Navigator.pushNamed(
86+
context,
87+
FormScreen.routeName,
88+
arguments: FormScreenArguments(
89+
AppLocalizations.of(context).addIngredient,
90+
MealItemForm(widget._meal, widget._listMealItems),
91+
hasListView: true,
92+
),
93+
);
94+
},
9095
),
91-
child: IconButton(
92-
icon: const Icon(Icons.history_edu),
93-
color: Colors.white,
96+
TextButton.icon(
97+
label: Text(AppLocalizations.of(context).editSchedule),
9498
onPressed: () {
95-
Provider.of<NutritionPlansProvider>(context, listen: false)
96-
.logMealToDiary(widget._meal);
97-
ScaffoldMessenger.of(context).showSnackBar(
98-
SnackBar(
99-
content: Text(
100-
AppLocalizations.of(context).mealLogged,
101-
textAlign: TextAlign.center,
102-
),
99+
Navigator.pushNamed(
100+
context,
101+
FormScreen.routeName,
102+
arguments: FormScreenArguments(
103+
AppLocalizations.of(context).edit,
104+
MealForm(widget._meal.planId, widget._meal),
103105
),
104106
);
105107
},
108+
icon: const Icon(Icons.timer),
106109
),
107-
),
108-
IconButton(
109-
onPressed: () {
110-
Navigator.pushNamed(
111-
context,
112-
FormScreen.routeName,
113-
arguments: FormScreenArguments(
114-
AppLocalizations.of(context).edit,
115-
MealForm(widget._meal.planId, widget._meal),
116-
),
117-
);
118-
},
119-
icon: const Icon(Icons.edit),
120-
),
121-
],
122-
),
123-
if (_expanded) const Divider(),
124-
...widget._meal.mealItems.map((item) => MealItemWidget(item, _expanded)),
125-
OutlinedButton(
126-
child: Text(AppLocalizations.of(context).addIngredient),
127-
onPressed: () {
128-
Navigator.pushNamed(
129-
context,
130-
FormScreen.routeName,
131-
arguments: FormScreenArguments(
132-
AppLocalizations.of(context).addIngredient,
133-
MealItemForm(widget._meal, widget._listMealItems),
134-
hasListView: true,
135-
),
136-
);
137-
},
138-
),
110+
TextButton.icon(
111+
onPressed: () {
112+
// Delete the meal
113+
Provider.of<NutritionPlansProvider>(context, listen: false)
114+
.deleteMeal(widget._meal);
115+
116+
// and inform the user
117+
ScaffoldMessenger.of(context).showSnackBar(
118+
SnackBar(
119+
content: Text(
120+
AppLocalizations.of(context).successfullyDeleted,
121+
textAlign: TextAlign.center,
122+
),
123+
),
124+
);
125+
},
126+
label: Text(AppLocalizations.of(context).delete),
127+
icon: const Icon(Icons.delete)),
128+
],
129+
)),
130+
const Divider(),
131+
...widget._meal.mealItems
132+
.map((item) => MealItemWidget(item, _showingDetails, _editing)),
139133
],
140134
),
141135
),
@@ -144,10 +138,11 @@ class _MealWidgetState extends State<MealWidget> {
144138
}
145139

146140
class MealItemWidget extends StatelessWidget {
147-
final bool _expanded;
141+
final bool _editing;
142+
final bool _showingDetails;
148143
final MealItem _item;
149144

150-
const MealItemWidget(this._item, this._expanded);
145+
const MealItemWidget(this._item, this._showingDetails, this._editing);
151146

152147
@override
153148
Widget build(BuildContext context) {
@@ -180,11 +175,12 @@ class MealItemWidget extends StatelessWidget {
180175
),
181176
subtitle: Column(
182177
crossAxisAlignment: CrossAxisAlignment.start,
183-
children: [if (_expanded) ...getMutedNutritionalValues(values, context)],
178+
children: [if (_showingDetails) ...getMutedNutritionalValues(values, context)],
184179
),
185-
trailing: _expanded
180+
trailing: _editing
186181
? IconButton(
187182
icon: const Icon(Icons.delete),
183+
tooltip: AppLocalizations.of(context).delete,
188184
iconSize: ICON_SIZE_SMALL,
189185
onPressed: () {
190186
// Delete the meal item
@@ -205,87 +201,95 @@ class MealItemWidget extends StatelessWidget {
205201
}
206202
}
207203

208-
class DismissibleMealHeader extends StatelessWidget {
209-
final bool _expanded;
210-
final Function _toggle;
204+
class MealHeader extends StatelessWidget {
205+
final bool _editing;
206+
final bool _showingDetails;
207+
final Function _toggleEditing;
208+
final Function _toggleDetails;
211209

212-
const DismissibleMealHeader(
213-
this._expanded,
214-
this._toggle, {
210+
const MealHeader({
215211
required Meal meal,
216-
}) : _meal = meal;
212+
required bool editing,
213+
required Function toggleEditing,
214+
required bool showingDetails,
215+
required Function toggleDetails,
216+
}) : _toggleDetails = toggleDetails,
217+
_toggleEditing = toggleEditing,
218+
_showingDetails = showingDetails,
219+
_editing = editing,
220+
_meal = meal;
217221

218222
final Meal _meal;
219223

220224
@override
221225
Widget build(BuildContext context) {
222-
return Dismissible(
223-
key: Key(_meal.id.toString()),
224-
direction: DismissDirection.startToEnd,
225-
background: Container(
226-
color: Theme.of(context).primaryColor, //wgerPrimaryButtonColor,
227-
alignment: Alignment.centerLeft,
228-
padding: const EdgeInsets.only(left: 10),
229-
child: Column(
230-
mainAxisAlignment: MainAxisAlignment.center,
231-
children: [
232-
Text(
233-
AppLocalizations.of(context).logMeal,
234-
style: const TextStyle(color: Colors.white),
226+
return Column(
227+
crossAxisAlignment: CrossAxisAlignment.start,
228+
children: [
229+
ListTile(
230+
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
231+
title: Row(children: [
232+
Expanded(
233+
child: (_meal.name != '')
234+
? Column(
235+
crossAxisAlignment: CrossAxisAlignment.start,
236+
children: [
237+
Text(
238+
_meal.name,
239+
style: Theme.of(context).textTheme.titleMedium,
240+
),
241+
Text(
242+
_meal.time!.format(context),
243+
style: Theme.of(context).textTheme.headlineSmall,
244+
)
245+
],
246+
)
247+
: Text(
248+
_meal.time!.format(context),
249+
style: Theme.of(context).textTheme.headlineSmall,
250+
),
235251
),
236-
const Icon(
237-
Icons.history_edu,
238-
color: Colors.white,
252+
Text(
253+
AppLocalizations.of(context).log,
254+
style: Theme.of(context)
255+
.textTheme
256+
.labelLarge
257+
?.copyWith(color: Theme.of(context).colorScheme.primary),
239258
),
240-
],
241-
),
242-
),
243-
confirmDismiss: (direction) async {
244-
// Delete
245-
if (direction == DismissDirection.startToEnd) {
246-
Provider.of<NutritionPlansProvider>(context, listen: false).logMealToDiary(_meal);
247-
ScaffoldMessenger.of(context).showSnackBar(
248-
SnackBar(
249-
content: Text(
250-
AppLocalizations.of(context).mealLogged,
251-
textAlign: TextAlign.center,
252-
),
259+
const SizedBox(width: 26),
260+
const SizedBox(height: 40, width: 1, child: VerticalDivider()),
261+
]),
262+
trailing: Row(mainAxisSize: MainAxisSize.min, children: [
263+
IconButton(
264+
icon: _showingDetails ? const Icon(Icons.info) : const Icon(Icons.info_outline),
265+
onPressed: () {
266+
_toggleDetails();
267+
},
268+
tooltip: AppLocalizations.of(context).toggleDetails,
253269
),
254-
);
255-
}
256-
return false;
257-
},
258-
child: Container(
259-
padding: const EdgeInsets.all(10),
260-
decoration: BoxDecoration(color: Theme.of(context).colorScheme.inversePrimary),
261-
child: Column(
262-
crossAxisAlignment: CrossAxisAlignment.start,
263-
children: [
264-
if (_meal.name != '')
265-
Text(
266-
_meal.name,
267-
style: Theme.of(context).textTheme.headlineSmall,
268-
),
269-
Row(
270-
children: [
271-
Expanded(
272-
child: Text(
273-
_meal.time!.format(context),
274-
style: Theme.of(context).textTheme.headlineSmall,
275-
),
276-
),
277-
IconButton(
278-
visualDensity: VisualDensity.compact,
279-
icon: _expanded ? const Icon(Icons.unfold_less) : const Icon(Icons.unfold_more),
280-
onPressed: () {
281-
_toggle();
282-
},
270+
const SizedBox(width: 5),
271+
IconButton(
272+
icon: _editing ? const Icon(Icons.done) : const Icon(Icons.edit),
273+
tooltip:
274+
_editing ? AppLocalizations.of(context).done : AppLocalizations.of(context).edit,
275+
onPressed: () {
276+
_toggleEditing();
277+
},
278+
)
279+
]),
280+
onTap: () {
281+
Provider.of<NutritionPlansProvider>(context, listen: false).logMealToDiary(_meal);
282+
ScaffoldMessenger.of(context).showSnackBar(
283+
SnackBar(
284+
content: Text(
285+
AppLocalizations.of(context).mealLogged,
286+
textAlign: TextAlign.center,
283287
),
284-
],
285-
),
286-
],
288+
),
289+
);
290+
},
287291
),
288-
),
292+
],
289293
);
290294
}
291295
}

lib/widgets/nutrition/nutritional_diary_detail.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class NutritionalDiaryDetailWidget extends StatelessWidget {
195195
),
196196
),
197197
IconButton(
198+
tooltip: AppLocalizations.of(context).delete,
198199
onPressed: () {
199200
Provider.of<NutritionPlansProvider>(context, listen: false)
200201
.deleteLog(log.id!, _nutritionalPlan.id!);

0 commit comments

Comments
 (0)