Skip to content

Commit d5898b5

Browse files
authored
Merge pull request #596 from wger-project/portion-size-slider-fiber-renames
Portion size slider fiber renames
2 parents c3dec29 + d5fa2b9 commit d5898b5

File tree

7 files changed

+34
-59
lines changed

7 files changed

+34
-59
lines changed

lib/models/nutrition/nutritional_plan.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class NutritionalPlan {
5656
@JsonKey(required: true, name: 'goal_fat')
5757
late num? goalFat;
5858

59-
@JsonKey(required: true, name: 'goal_fibers')
60-
late num? goalFibers;
59+
@JsonKey(required: true, name: 'goal_fiber')
60+
late num? goalFiber;
6161

6262
@JsonKey(includeFromJson: false, includeToJson: false, defaultValue: [])
6363
List<Meal> meals = [];
@@ -74,7 +74,7 @@ class NutritionalPlan {
7474
this.goalProtein,
7575
this.goalCarbohydrates,
7676
this.goalFat,
77-
this.goalFibers,
77+
this.goalFiber,
7878
List<Meal>? meals,
7979
List<Log>? diaryEntries,
8080
}) {
@@ -89,7 +89,7 @@ class NutritionalPlan {
8989
goalEnergy = null;
9090
goalProtein = null;
9191
goalCarbohydrates = null;
92-
goalFibers = null;
92+
goalFiber = null;
9393
goalFat = null;
9494
}
9595

@@ -110,7 +110,7 @@ class NutritionalPlan {
110110
}
111111

112112
bool get hasAnyAdvancedGoals {
113-
return goalFibers != null;
113+
return goalFiber != null;
114114
}
115115

116116
/// Calculations
@@ -126,7 +126,7 @@ class NutritionalPlan {
126126
fat: goalFat?.toDouble(),
127127
protein: goalProtein?.toDouble(),
128128
carbohydrates: goalCarbohydrates?.toDouble(),
129-
fiber: goalFibers?.toDouble(),
129+
fiber: goalFiber?.toDouble(),
130130
);
131131
}
132132
// if there are no set goals and no defined meals, the goals are still undefined

lib/models/nutrition/nutritional_plan.g.dart

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/screens/log_meal_screen.dart

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
*/
1818

1919
import 'package:flutter/material.dart';
20-
import 'package:flutter/services.dart';
2120
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2221
import 'package:provider/provider.dart';
2322
import 'package:wger/models/nutrition/meal.dart';
24-
import 'package:wger/models/nutrition/meal_item.dart';
2523
import 'package:wger/providers/nutrition.dart';
2624
import 'package:wger/widgets/nutrition/meal.dart';
2725
import 'package:wger/widgets/nutrition/widgets.dart';
@@ -40,25 +38,11 @@ class LogMealScreen extends StatefulWidget {
4038
}
4139

4240
class _LogMealScreenState extends State<LogMealScreen> {
43-
late TextEditingController _controller;
44-
int portionPct = 100;
45-
46-
@override
47-
void initState() {
48-
super.initState();
49-
_controller = TextEditingController();
50-
}
51-
52-
@override
53-
void dispose() {
54-
_controller.dispose();
55-
super.dispose();
56-
}
41+
double portionPct = 100;
5742

5843
@override
5944
Widget build(BuildContext context) {
6045
final args = ModalRoute.of(context)!.settings.arguments as LogMealArguments;
61-
_controller.text = portionPct.toString();
6246
final meal = args.meal.copyWith(
6347
mealItems: args.meal.mealItems
6448
.map((mealItem) => mealItem.copyWith(amount: mealItem.amount * portionPct / 100))
@@ -71,7 +55,10 @@ class _LogMealScreenState extends State<LogMealScreen> {
7155
body: Consumer<NutritionPlansProvider>(
7256
builder: (context, nutritionProvider, child) => SingleChildScrollView(
7357
child: Padding(
74-
padding: const EdgeInsets.all(8.0),
58+
padding: const EdgeInsets.symmetric(
59+
horizontal: 8,
60+
vertical: 16,
61+
),
7562
child: Column(
7663
children: [
7764
Text(meal.name, style: Theme.of(context).textTheme.headlineSmall),
@@ -83,28 +70,17 @@ class _LogMealScreenState extends State<LogMealScreen> {
8370
const NutritionDiaryheader(),
8471
...meal.mealItems
8572
.map((item) => MealItemWidget(item, viewMode.withAllDetails, false)),
86-
Row(
87-
children: [
88-
Text('Portion size'),
89-
Expanded(
90-
child: TextField(
91-
maxLength: 4,
92-
maxLengthEnforcement: MaxLengthEnforcement.enforced,
93-
keyboardType: TextInputType.number,
94-
decoration: InputDecoration(
95-
hintText: 'Enter the portion size as a percent',
96-
),
97-
controller: _controller,
98-
onChanged: (value) {
99-
var v = int.tryParse(value);
100-
if (v == null) return;
101-
setState(() {
102-
portionPct = v;
103-
});
104-
},
105-
),
106-
),
107-
],
73+
const SizedBox(height: 32),
74+
Text(
75+
'Portion: ${portionPct.round()} %',
76+
style: Theme.of(context).textTheme.bodyLarge,
77+
),
78+
Slider.adaptive(
79+
min: 0,
80+
max: 150,
81+
divisions: 30,
82+
onChanged: (value) => setState(() => portionPct = value),
83+
value: portionPct,
10884
),
10985
],
11086
),

lib/widgets/nutrition/charts.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class NutritionalDiaryChartWidgetFlState extends State<NutritionalDiaryChartWidg
401401
barchartGroup(3, barsSpace, barsWidth, 'fat'),
402402
barchartGroup(4, barsSpace, barsWidth, 'fatSaturated'),
403403
if (widget._nutritionalPlan.nutritionalGoals.fiber != null)
404-
barchartGroup(5, barsSpace, barsWidth, 'fibers'),
404+
barchartGroup(5, barsSpace, barsWidth, 'fiber'),
405405
],
406406
),
407407
),

lib/widgets/nutrition/forms.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,9 @@ class _PlanFormState extends State<PlanForm> {
512512
widget._plan.goalProtein = null;
513513
widget._plan.goalCarbohydrates = null;
514514
widget._plan.goalFat = null;
515-
widget._plan.goalFibers = null;
515+
widget._plan.goalFiber = null;
516516
case GoalType.basic:
517-
widget._plan.goalFibers = null;
517+
widget._plan.goalFiber = null;
518518
break;
519519
default:
520520
break;
@@ -562,11 +562,11 @@ class _PlanFormState extends State<PlanForm> {
562562

563563
if (_goalType == GoalType.advanced)
564564
GoalMacros(
565-
val: widget._plan.goalFibers?.toString(),
565+
val: widget._plan.goalFiber?.toString(),
566566
label: AppLocalizations.of(context).goalFiber,
567567
suffix: AppLocalizations.of(context).g,
568-
onSave: (double value) => widget._plan.goalFibers = value,
569-
key: const Key('field-goal-fibers'),
568+
onSave: (double value) => widget._plan.goalFiber = value,
569+
key: const Key('field-goal-fiber'),
570570
),
571571
ElevatedButton(
572572
key: const Key(SUBMIT_BUTTON_KEY_NAME),

test/fixtures/nutrition/nutritional_plan_detail_response.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"goal_protein": null,
88
"goal_carbohydrates": null,
99
"goal_fat": null,
10-
"goal_fibers": null,
10+
"goal_fiber": null,
1111
"language": 1
1212
}

test/fixtures/nutrition/nutritional_plan_info_detail_response.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"goal_protein": null,
1212
"goal_carbohydrates": null,
1313
"goal_fat": null,
14-
"goal_fibers": null,
14+
"goal_fiber": null,
1515
"description": "",
1616
"get_nutritional_values": {
1717
"total": {

0 commit comments

Comments
 (0)