Skip to content

Commit 67cd227

Browse files
committed
use slider for portion size, layout tweaks
1 parent c3dec29 commit 67cd227

File tree

1 file changed

+16
-40
lines changed

1 file changed

+16
-40
lines changed

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
),

0 commit comments

Comments
 (0)