mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Add quick access to logged products #79
This commit is contained in:
@@ -480,6 +480,10 @@
|
||||
"@selectIngredient": {
|
||||
"description": "Error message when the user hasn't selected an ingredient from the autocompleter"
|
||||
},
|
||||
"recentlyUsedIngredients": "Recently used ingredients. Please select one of ingredients.",
|
||||
"@recentlyUsedIngredients": {
|
||||
"description": "A message when a user adds a new ingredient to a meal."
|
||||
},
|
||||
"selectImage": "Please select an image",
|
||||
"@selectImage": {
|
||||
"description": "Label and error message when the user hasn't selected an image to save"
|
||||
|
||||
@@ -29,6 +29,7 @@ import 'package:wger/models/nutrition/meal_item.dart';
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/screens/nutritional_plan_screen.dart';
|
||||
import 'package:wger/widgets/nutrition/meal.dart';
|
||||
|
||||
class MealForm extends StatelessWidget {
|
||||
late Meal _meal;
|
||||
@@ -115,8 +116,9 @@ class MealForm extends StatelessWidget {
|
||||
class MealItemForm extends StatelessWidget {
|
||||
final Meal _meal;
|
||||
late MealItem _mealItem;
|
||||
final List<IngredientMeal> _listOfIngredientMeal;
|
||||
|
||||
MealItemForm(this._meal, [mealItem]) {
|
||||
MealItemForm(this._meal, this._listOfIngredientMeal, [mealItem]) {
|
||||
_mealItem = mealItem ?? MealItem.empty();
|
||||
_mealItem.mealId = _meal.id!;
|
||||
}
|
||||
@@ -127,6 +129,7 @@ class MealItemForm extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final String unit = AppLocalizations.of(context).g;
|
||||
return Container(
|
||||
margin: EdgeInsets.all(20),
|
||||
child: Form(
|
||||
@@ -200,6 +203,51 @@ class MealItemForm extends StatelessWidget {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
if (_listOfIngredientMeal.isNotEmpty) SizedBox(height: 10.0),
|
||||
Container(
|
||||
child: Text(AppLocalizations.of(context).recentlyUsedIngredients),
|
||||
padding: EdgeInsets.all(10.0)),
|
||||
Expanded(
|
||||
child: Scrollbar(
|
||||
isAlwaysShown: true,
|
||||
child: ListView.builder(
|
||||
itemCount: _listOfIngredientMeal.length,
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (context, index) {
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: TextButton(
|
||||
child: Text(
|
||||
'${_listOfIngredientMeal[index].ingredientQuantity.toStringAsFixed(0)}$unit ${_listOfIngredientMeal[index].ingredientName}',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
onPressed: () {
|
||||
_ingredientController.text =
|
||||
_listOfIngredientMeal[index].ingredientName;
|
||||
_amountController.text =
|
||||
_listOfIngredientMeal[index]
|
||||
.ingredientQuantity
|
||||
.toStringAsFixed(0);
|
||||
_mealItem.ingredientId =
|
||||
_listOfIngredientMeal[index].ingredientCode;
|
||||
_mealItem.amount = _listOfIngredientMeal[index]
|
||||
.ingredientQuantity;
|
||||
},
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -30,9 +30,11 @@ import 'package:wger/widgets/nutrition/helpers.dart';
|
||||
|
||||
class MealWidget extends StatefulWidget {
|
||||
final Meal _meal;
|
||||
final List<IngredientMeal> _listOfIngredientMeal;
|
||||
|
||||
const MealWidget(
|
||||
this._meal,
|
||||
this._listOfIngredientMeal,
|
||||
);
|
||||
|
||||
@override
|
||||
@@ -127,7 +129,7 @@ class _MealWidgetState extends State<MealWidget> {
|
||||
FormScreen.routeName,
|
||||
arguments: FormScreenArguments(
|
||||
AppLocalizations.of(context).addIngredient,
|
||||
MealItemForm(widget._meal),
|
||||
MealItemForm(widget._meal, widget._listOfIngredientMeal),
|
||||
hasListView: true,
|
||||
),
|
||||
);
|
||||
@@ -140,6 +142,18 @@ class _MealWidgetState extends State<MealWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
class IngredientMeal {
|
||||
final int ingredientCode;
|
||||
final num ingredientQuantity;
|
||||
final String ingredientName;
|
||||
|
||||
const IngredientMeal(
|
||||
this.ingredientCode,
|
||||
this.ingredientQuantity,
|
||||
this.ingredientName,
|
||||
);
|
||||
}
|
||||
|
||||
class MealItemWidget extends StatelessWidget {
|
||||
final bool _expanded;
|
||||
final MealItem _item;
|
||||
|
||||
@@ -44,11 +44,23 @@ class NutritionalPlanDetailWidget extends StatelessWidget {
|
||||
? _nutritionalPlan.gPerBodyKg(lastWeightEntry.weight, nutritionalValues)
|
||||
: null;
|
||||
|
||||
final List<IngredientMeal> listOfIngredientMeal = [];
|
||||
for (final meal in _nutritionalPlan.meals) {
|
||||
for (final mealItems in meal.mealItems) {
|
||||
final ingredientInList = listOfIngredientMeal.where(
|
||||
(element) => element.ingredientCode == mealItems.ingredientId);
|
||||
if (ingredientInList.isEmpty) {
|
||||
listOfIngredientMeal.add(IngredientMeal(mealItems.ingredientId,
|
||||
mealItems.amount, mealItems.ingredientObj.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return SliverList(
|
||||
delegate: SliverChildListDelegate(
|
||||
[
|
||||
SizedBox(height: 10),
|
||||
..._nutritionalPlan.meals.map((meal) => MealWidget(meal)).toList(),
|
||||
..._nutritionalPlan.meals.map((meal) => MealWidget(meal, listOfIngredientMeal)).toList(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ElevatedButton(
|
||||
|
||||
Reference in New Issue
Block a user