Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/models/nutrition/nutritional_plan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class NutritionalPlan {
@JsonKey(required: true, name: 'goal_fat')
late num? goalFat;

@JsonKey(required: true, name: 'goal_fibers')
late num? goalFibers;
@JsonKey(required: true, name: 'goal_fiber')
late num? goalFiber;

@JsonKey(includeFromJson: false, includeToJson: false, defaultValue: [])
List<Meal> meals = [];
Expand All @@ -74,7 +74,7 @@ class NutritionalPlan {
this.goalProtein,
this.goalCarbohydrates,
this.goalFat,
this.goalFibers,
this.goalFiber,
List<Meal>? meals,
List<Log>? diaryEntries,
}) {
Expand All @@ -89,7 +89,7 @@ class NutritionalPlan {
goalEnergy = null;
goalProtein = null;
goalCarbohydrates = null;
goalFibers = null;
goalFiber = null;
goalFat = null;
}

Expand All @@ -110,7 +110,7 @@ class NutritionalPlan {
}

bool get hasAnyAdvancedGoals {
return goalFibers != null;
return goalFiber != null;
}

/// Calculations
Expand All @@ -126,7 +126,7 @@ class NutritionalPlan {
fat: goalFat?.toDouble(),
protein: goalProtein?.toDouble(),
carbohydrates: goalCarbohydrates?.toDouble(),
fiber: goalFibers?.toDouble(),
fiber: goalFiber?.toDouble(),
);
}
// if there are no set goals and no defined meals, the goals are still undefined
Expand Down
9 changes: 4 additions & 5 deletions lib/models/nutrition/nutritional_plan.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 16 additions & 40 deletions lib/screens/log_meal_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
*/

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:provider/provider.dart';
import 'package:wger/models/nutrition/meal.dart';
import 'package:wger/models/nutrition/meal_item.dart';
import 'package:wger/providers/nutrition.dart';
import 'package:wger/widgets/nutrition/meal.dart';
import 'package:wger/widgets/nutrition/widgets.dart';
Expand All @@ -40,25 +38,11 @@ class LogMealScreen extends StatefulWidget {
}

class _LogMealScreenState extends State<LogMealScreen> {
late TextEditingController _controller;
int portionPct = 100;

@override
void initState() {
super.initState();
_controller = TextEditingController();
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}
double portionPct = 100;

@override
Widget build(BuildContext context) {
final args = ModalRoute.of(context)!.settings.arguments as LogMealArguments;
_controller.text = portionPct.toString();
final meal = args.meal.copyWith(
mealItems: args.meal.mealItems
.map((mealItem) => mealItem.copyWith(amount: mealItem.amount * portionPct / 100))
Expand All @@ -71,7 +55,10 @@ class _LogMealScreenState extends State<LogMealScreen> {
body: Consumer<NutritionPlansProvider>(
builder: (context, nutritionProvider, child) => SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 16,
),
child: Column(
children: [
Text(meal.name, style: Theme.of(context).textTheme.headlineSmall),
Expand All @@ -83,28 +70,17 @@ class _LogMealScreenState extends State<LogMealScreen> {
const NutritionDiaryheader(),
...meal.mealItems
.map((item) => MealItemWidget(item, viewMode.withAllDetails, false)),
Row(
children: [
Text('Portion size'),
Expanded(
child: TextField(
maxLength: 4,
maxLengthEnforcement: MaxLengthEnforcement.enforced,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'Enter the portion size as a percent',
),
controller: _controller,
onChanged: (value) {
var v = int.tryParse(value);
if (v == null) return;
setState(() {
portionPct = v;
});
},
),
),
],
const SizedBox(height: 32),
Text(
'Portion: ${portionPct.round()} %',
style: Theme.of(context).textTheme.bodyLarge,
),
Slider.adaptive(
min: 0,
max: 150,
divisions: 30,
onChanged: (value) => setState(() => portionPct = value),
value: portionPct,
),
],
),
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/nutrition/charts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class NutritionalDiaryChartWidgetFlState extends State<NutritionalDiaryChartWidg
barchartGroup(3, barsSpace, barsWidth, 'fat'),
barchartGroup(4, barsSpace, barsWidth, 'fatSaturated'),
if (widget._nutritionalPlan.nutritionalGoals.fiber != null)
barchartGroup(5, barsSpace, barsWidth, 'fibers'),
barchartGroup(5, barsSpace, barsWidth, 'fiber'),
],
),
),
Expand Down
10 changes: 5 additions & 5 deletions lib/widgets/nutrition/forms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ class _PlanFormState extends State<PlanForm> {
widget._plan.goalProtein = null;
widget._plan.goalCarbohydrates = null;
widget._plan.goalFat = null;
widget._plan.goalFibers = null;
widget._plan.goalFiber = null;
case GoalType.basic:
widget._plan.goalFibers = null;
widget._plan.goalFiber = null;
break;
default:
break;
Expand Down Expand Up @@ -562,11 +562,11 @@ class _PlanFormState extends State<PlanForm> {

if (_goalType == GoalType.advanced)
GoalMacros(
val: widget._plan.goalFibers?.toString(),
val: widget._plan.goalFiber?.toString(),
label: AppLocalizations.of(context).goalFiber,
suffix: AppLocalizations.of(context).g,
onSave: (double value) => widget._plan.goalFibers = value,
key: const Key('field-goal-fibers'),
onSave: (double value) => widget._plan.goalFiber = value,
key: const Key('field-goal-fiber'),
),
ElevatedButton(
key: const Key(SUBMIT_BUTTON_KEY_NAME),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"goal_protein": null,
"goal_carbohydrates": null,
"goal_fat": null,
"goal_fibers": null,
"goal_fiber": null,
"language": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"goal_protein": null,
"goal_carbohydrates": null,
"goal_fat": null,
"goal_fibers": null,
"goal_fiber": null,
"description": "",
"get_nutritional_values": {
"total": {
Expand Down