@@ -43,11 +43,18 @@ class MealWidget extends StatefulWidget {
43
43
}
44
44
45
45
class _MealWidgetState extends State <MealWidget > {
46
- bool _expanded = false ;
46
+ bool _showingDetails = false ;
47
+ bool _editing = false ;
47
48
48
- void _toggleExpanded () {
49
+ void _toggleEditing () {
49
50
setState (() {
50
- _expanded = ! _expanded;
51
+ _editing = ! _editing;
52
+ });
53
+ }
54
+
55
+ void _toggleDetails () {
56
+ setState (() {
57
+ _showingDetails = ! _showingDetails;
51
58
});
52
59
}
53
60
@@ -57,85 +64,72 @@ class _MealWidgetState extends State<MealWidget> {
57
64
padding: const EdgeInsets .all (3 ),
58
65
child: Card (
59
66
child: Column (
67
+ crossAxisAlignment: CrossAxisAlignment .start,
60
68
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
+ },
90
95
),
91
- child: IconButton (
92
- icon: const Icon (Icons .history_edu),
93
- color: Colors .white,
96
+ TextButton .icon (
97
+ label: Text (AppLocalizations .of (context).editSchedule),
94
98
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),
103
105
),
104
106
);
105
107
},
108
+ icon: const Icon (Icons .timer),
106
109
),
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)),
139
133
],
140
134
),
141
135
),
@@ -144,10 +138,11 @@ class _MealWidgetState extends State<MealWidget> {
144
138
}
145
139
146
140
class MealItemWidget extends StatelessWidget {
147
- final bool _expanded;
141
+ final bool _editing;
142
+ final bool _showingDetails;
148
143
final MealItem _item;
149
144
150
- const MealItemWidget (this ._item, this ._expanded );
145
+ const MealItemWidget (this ._item, this ._showingDetails, this ._editing );
151
146
152
147
@override
153
148
Widget build (BuildContext context) {
@@ -180,11 +175,12 @@ class MealItemWidget extends StatelessWidget {
180
175
),
181
176
subtitle: Column (
182
177
crossAxisAlignment: CrossAxisAlignment .start,
183
- children: [if (_expanded ) ...getMutedNutritionalValues (values, context)],
178
+ children: [if (_showingDetails ) ...getMutedNutritionalValues (values, context)],
184
179
),
185
- trailing: _expanded
180
+ trailing: _editing
186
181
? IconButton (
187
182
icon: const Icon (Icons .delete),
183
+ tooltip: AppLocalizations .of (context).delete,
188
184
iconSize: ICON_SIZE_SMALL ,
189
185
onPressed: () {
190
186
// Delete the meal item
@@ -205,87 +201,95 @@ class MealItemWidget extends StatelessWidget {
205
201
}
206
202
}
207
203
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;
211
209
212
- const DismissibleMealHeader (
213
- this ._expanded,
214
- this ._toggle, {
210
+ const MealHeader ({
215
211
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;
217
221
218
222
final Meal _meal;
219
223
220
224
@override
221
225
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
+ ),
235
251
),
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),
239
258
),
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,
253
269
),
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,
283
287
),
284
- ] ,
285
- ),
286
- ] ,
288
+ ) ,
289
+ );
290
+ } ,
287
291
),
288
- ) ,
292
+ ] ,
289
293
);
290
294
}
291
295
}
0 commit comments