17
17
*/
18
18
19
19
import 'package:flutter/material.dart' ;
20
- import 'package:flutter/services.dart' ;
21
20
import 'package:flutter_gen/gen_l10n/app_localizations.dart' ;
22
21
import 'package:provider/provider.dart' ;
23
22
import 'package:wger/models/nutrition/meal.dart' ;
24
- import 'package:wger/models/nutrition/meal_item.dart' ;
25
23
import 'package:wger/providers/nutrition.dart' ;
26
24
import 'package:wger/widgets/nutrition/meal.dart' ;
27
25
import 'package:wger/widgets/nutrition/widgets.dart' ;
@@ -40,25 +38,11 @@ class LogMealScreen extends StatefulWidget {
40
38
}
41
39
42
40
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 ;
57
42
58
43
@override
59
44
Widget build (BuildContext context) {
60
45
final args = ModalRoute .of (context)! .settings.arguments as LogMealArguments ;
61
- _controller.text = portionPct.toString ();
62
46
final meal = args.meal.copyWith (
63
47
mealItems: args.meal.mealItems
64
48
.map ((mealItem) => mealItem.copyWith (amount: mealItem.amount * portionPct / 100 ))
@@ -71,7 +55,10 @@ class _LogMealScreenState extends State<LogMealScreen> {
71
55
body: Consumer <NutritionPlansProvider >(
72
56
builder: (context, nutritionProvider, child) => SingleChildScrollView (
73
57
child: Padding (
74
- padding: const EdgeInsets .all (8.0 ),
58
+ padding: const EdgeInsets .symmetric (
59
+ horizontal: 8 ,
60
+ vertical: 16 ,
61
+ ),
75
62
child: Column (
76
63
children: [
77
64
Text (meal.name, style: Theme .of (context).textTheme.headlineSmall),
@@ -83,28 +70,17 @@ class _LogMealScreenState extends State<LogMealScreen> {
83
70
const NutritionDiaryheader (),
84
71
...meal.mealItems
85
72
.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,
108
84
),
109
85
],
110
86
),
0 commit comments