Skip to content

Commit a77a0cc

Browse files
committed
Show last logged items for quick access
1 parent fbff8f5 commit a77a0cc

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

lib/screens/nutritional_plan_screen.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class NutritionalPlanScreen extends StatelessWidget {
5353
arguments: FormScreenArguments(
5454
AppLocalizations.of(context).logIngredient,
5555
IngredientLogForm(_nutritionalPlan),
56+
hasListView: true,
5657
),
5758
);
5859
},

lib/widgets/dashboard/widgets.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
210210
arguments: FormScreenArguments(
211211
AppLocalizations.of(context).logIngredient,
212212
IngredientLogForm(_plan!),
213+
hasListView: true,
213214
),
214215
);
215216
},

lib/widgets/nutrition/forms.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ class IngredientLogForm extends StatelessWidget {
226226

227227
@override
228228
Widget build(BuildContext context) {
229+
final diaryEntries = _plan.logs;
230+
final String unit = AppLocalizations.of(context).g;
231+
229232
return Container(
230233
margin: const EdgeInsets.all(20),
231234
child: Form(
@@ -295,6 +298,34 @@ class IngredientLogForm extends StatelessWidget {
295298
Navigator.of(context).pop();
296299
},
297300
),
301+
if (diaryEntries.isNotEmpty) const SizedBox(height: 10.0),
302+
Container(
303+
child: Text(AppLocalizations.of(context).recentlyUsedIngredients),
304+
padding: const EdgeInsets.all(10.0),
305+
),
306+
Expanded(
307+
child: ListView.builder(
308+
itemCount: diaryEntries.length,
309+
shrinkWrap: true,
310+
itemBuilder: (context, index) {
311+
return Card(
312+
child: ListTile(
313+
onTap: () {
314+
_ingredientController.text = diaryEntries[index].ingredientObj.name;
315+
_ingredientIdController.text =
316+
diaryEntries[index].ingredientObj.id.toString();
317+
_amountController.text = diaryEntries[index].amount.toStringAsFixed(0);
318+
_mealItem.ingredientId = diaryEntries[index].ingredientId;
319+
_mealItem.amount = diaryEntries[index].amount;
320+
},
321+
title: Text(_plan.logs[index].ingredientObj.name),
322+
subtitle: Text('${diaryEntries[index].amount.toStringAsFixed(0)}$unit'),
323+
trailing: const Icon(Icons.copy),
324+
),
325+
);
326+
},
327+
),
328+
)
298329
],
299330
),
300331
),

0 commit comments

Comments
 (0)