16
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
*/
18
18
19
+ import 'package:carousel_slider/carousel_slider.dart' ;
19
20
import 'package:flutter/material.dart' ;
20
21
import 'package:flutter/widgets.dart' ;
21
22
import 'package:flutter_gen/gen_l10n/app_localizations.dart' ;
@@ -35,14 +36,20 @@ import 'package:wger/screens/workout_plan_screen.dart';
35
36
import 'package:wger/theme/theme.dart' ;
36
37
import 'package:wger/widgets/core/charts.dart' ;
37
38
import 'package:wger/widgets/core/core.dart' ;
39
+ import 'package:wger/widgets/measurements/categories_card.dart' ;
38
40
import 'package:wger/widgets/nutrition/charts.dart' ;
39
41
import 'package:wger/widgets/nutrition/forms.dart' ;
40
42
import 'package:wger/widgets/weight/forms.dart' ;
41
43
import 'package:wger/widgets/workouts/forms.dart' ;
42
44
45
+ import '../../providers/measurement.dart' ;
46
+ import '../../screens/measurement_entries_screen.dart' ;
47
+ import '../measurements/forms.dart' ;
48
+
43
49
class DashboardNutritionWidget extends StatefulWidget {
44
50
@override
45
- _DashboardNutritionWidgetState createState () => _DashboardNutritionWidgetState ();
51
+ _DashboardNutritionWidgetState createState () =>
52
+ _DashboardNutritionWidgetState ();
46
53
}
47
54
48
55
class _DashboardNutritionWidgetState extends State <DashboardNutritionWidget > {
@@ -53,7 +60,8 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
53
60
@override
54
61
void initState () {
55
62
super .initState ();
56
- _plan = Provider .of <NutritionPlansProvider >(context, listen: false ).currentPlan;
63
+ _plan =
64
+ Provider .of <NutritionPlansProvider >(context, listen: false ).currentPlan;
57
65
_hasContent = _plan != null ;
58
66
}
59
67
@@ -96,7 +104,8 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
96
104
icon: const Icon (Icons .history_edu),
97
105
color: wgerPrimaryButtonColor,
98
106
onPressed: () {
99
- Provider .of <NutritionPlansProvider >(context, listen: false ).logMealToDiary (meal);
107
+ Provider .of <NutritionPlansProvider >(context, listen: false )
108
+ .logMealToDiary (meal);
100
109
ScaffoldMessenger .of (context).showSnackBar (
101
110
SnackBar (
102
111
content: Text (
@@ -127,7 +136,8 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
127
136
),
128
137
),
129
138
const SizedBox (width: 5 ),
130
- Text ('${item .amount .toStringAsFixed (0 )} ${AppLocalizations .of (context ).g }' ),
139
+ Text (
140
+ '${item .amount .toStringAsFixed (0 )} ${AppLocalizations .of (context ).g }' ),
131
141
],
132
142
),
133
143
],
@@ -147,7 +157,9 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
147
157
return const Text ('' );
148
158
}
149
159
150
- return _showDetail ? const Icon (Icons .expand_less) : const Icon (Icons .expand_more);
160
+ return _showDetail
161
+ ? const Icon (Icons .expand_less)
162
+ : const Icon (Icons .expand_more);
151
163
}
152
164
153
165
@override
@@ -157,7 +169,9 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
157
169
children: [
158
170
ListTile (
159
171
title: Text (
160
- _hasContent ? _plan! .description : AppLocalizations .of (context).nutritionalPlan,
172
+ _hasContent
173
+ ? _plan! .description
174
+ : AppLocalizations .of (context).nutritionalPlan,
161
175
style: Theme .of (context).textTheme.headline4,
162
176
),
163
177
subtitle: Text (
@@ -186,7 +200,8 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
186
200
Container (
187
201
padding: const EdgeInsets .all (15 ),
188
202
height: 180 ,
189
- child: NutritionalPlanPieChartWidget (_plan! .nutritionalValues),
203
+ child:
204
+ NutritionalPlanPieChartWidget (_plan! .nutritionalValues),
190
205
)
191
206
],
192
207
),
@@ -218,8 +233,9 @@ class _DashboardNutritionWidgetState extends State<DashboardNutritionWidget> {
218
233
TextButton (
219
234
child: Text (AppLocalizations .of (context).goToDetailPage),
220
235
onPressed: () {
221
- Navigator .of (context)
222
- .pushNamed (NutritionalPlanScreen .routeName, arguments: _plan);
236
+ Navigator .of (context).pushNamed (
237
+ NutritionalPlanScreen .routeName,
238
+ arguments: _plan);
223
239
},
224
240
),
225
241
],
@@ -253,7 +269,7 @@ class _DashboardWeightWidgetState extends State<DashboardWeightWidget> {
253
269
style: Theme .of (context).textTheme.headline4,
254
270
),
255
271
leading: const FaIcon (
256
- FontAwesomeIcons .weightScale ,
272
+ FontAwesomeIcons .weight ,
257
273
color: Colors .black,
258
274
),
259
275
trailing: IconButton (
@@ -286,9 +302,11 @@ class _DashboardWeightWidgetState extends State<DashboardWeightWidget> {
286
302
mainAxisAlignment: MainAxisAlignment .end,
287
303
children: < Widget > [
288
304
TextButton (
289
- child: Text (AppLocalizations .of (context).goToDetailPage),
305
+ child: Text (
306
+ AppLocalizations .of (context).goToDetailPage),
290
307
onPressed: () {
291
- Navigator .of (context).pushNamed (WeightScreen .routeName);
308
+ Navigator .of (context)
309
+ .pushNamed (WeightScreen .routeName);
292
310
}),
293
311
],
294
312
),
@@ -309,6 +327,101 @@ class _DashboardWeightWidgetState extends State<DashboardWeightWidget> {
309
327
}
310
328
}
311
329
330
+ class DashboardMeasurementsWidget extends StatefulWidget {
331
+ @override
332
+ _DashboardMeasurementsWidgetState createState () =>
333
+ _DashboardMeasurementsWidgetState ();
334
+ }
335
+
336
+ class _DashboardMeasurementsWidgetState
337
+ extends State <DashboardMeasurementsWidget > {
338
+ int _current = 0 ;
339
+ final CarouselController _controller = CarouselController ();
340
+
341
+ @override
342
+ Widget build (BuildContext context) {
343
+ final _provider = Provider .of <MeasurementProvider >(context, listen: false );
344
+
345
+ var items = _provider.categories
346
+ .map (
347
+ (item) => CategoriesCard (item),
348
+ )
349
+ .toList ();
350
+ return Consumer <BodyWeightProvider >(
351
+ builder: (context, workoutProvider, child) => Card (
352
+ child: Column (
353
+ mainAxisSize: MainAxisSize .min,
354
+ children: [
355
+ ListTile (
356
+ title: Text (
357
+ AppLocalizations .of (context).measurements,
358
+ style: Theme .of (context).textTheme.headline4,
359
+ ),
360
+ leading: const FaIcon (
361
+ FontAwesomeIcons .weight,
362
+ color: Colors .black,
363
+ ),
364
+ ),
365
+ Column (
366
+ children: [
367
+ if (items.isNotEmpty)
368
+ Column (children: [
369
+ CarouselSlider (
370
+ items: items,
371
+ carouselController: _controller,
372
+ options: CarouselOptions (
373
+ autoPlay: false ,
374
+ enlargeCenterPage: false ,
375
+ viewportFraction: 1 ,
376
+ enableInfiniteScroll: false ,
377
+ aspectRatio: 1.1 ,
378
+ onPageChanged: (index, reason) {
379
+ setState (() {
380
+ _current = index;
381
+ });
382
+ }),
383
+ ),
384
+ Padding (
385
+ padding: const EdgeInsets .only (bottom: 10 ),
386
+ child: Row (
387
+ mainAxisAlignment: MainAxisAlignment .center,
388
+ children: items.asMap ().entries.map ((entry) {
389
+ return GestureDetector (
390
+ onTap: () => _controller.animateToPage (entry.key),
391
+ child: Container (
392
+ width: 12.0 ,
393
+ height: 12.0 ,
394
+ margin: EdgeInsets .symmetric (
395
+ vertical: 8.0 , horizontal: 4.0 ),
396
+ decoration: BoxDecoration (
397
+ shape: BoxShape .circle,
398
+ color: (Theme .of (context).brightness ==
399
+ Brightness .dark
400
+ ? Colors .white
401
+ : wgerPrimaryColor)
402
+ .withOpacity (
403
+ _current == entry.key ? 0.9 : 0.4 )),
404
+ ),
405
+ );
406
+ }).toList (),
407
+ ),
408
+ ),
409
+ ])
410
+ else
411
+ NothingFound (
412
+ AppLocalizations .of (context).noWeightEntries,
413
+ AppLocalizations .of (context).newEntry,
414
+ WeightForm (),
415
+ ),
416
+ ],
417
+ ),
418
+ ],
419
+ ),
420
+ ),
421
+ );
422
+ }
423
+ }
424
+
312
425
class DashboardWorkoutWidget extends StatefulWidget {
313
426
@override
314
427
_DashboardWorkoutWidgetState createState () => _DashboardWorkoutWidgetState ();
@@ -332,7 +445,9 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
332
445
return const Text ('' );
333
446
}
334
447
335
- return _showDetail ? const Icon (Icons .expand_less) : const Icon (Icons .expand_more);
448
+ return _showDetail
449
+ ? const Icon (Icons .expand_less)
450
+ : const Icon (Icons .expand_more);
336
451
}
337
452
338
453
List <Widget > getContent () {
@@ -364,7 +479,8 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
364
479
icon: const Icon (Icons .play_arrow),
365
480
color: wgerPrimaryButtonColor,
366
481
onPressed: () {
367
- Navigator .of (context).pushNamed (GymModeScreen .routeName, arguments: day);
482
+ Navigator .of (context)
483
+ .pushNamed (GymModeScreen .routeName, arguments: day);
368
484
},
369
485
),
370
486
],
@@ -386,7 +502,8 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
386
502
children: [
387
503
Text (s.exerciseObj.name),
388
504
const SizedBox (width: 10 ),
389
- MutedText (set .getSmartRepr (s.exerciseObj).join ('\n ' )),
505
+ MutedText (
506
+ set .getSmartRepr (s.exerciseObj).join ('\n ' )),
390
507
],
391
508
),
392
509
const SizedBox (height: 10 ),
@@ -411,7 +528,9 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
411
528
children: [
412
529
ListTile (
413
530
title: Text (
414
- _hasContent ? _workoutPlan! .name : AppLocalizations .of (context).labelWorkoutPlan,
531
+ _hasContent
532
+ ? _workoutPlan! .name
533
+ : AppLocalizations .of (context).labelWorkoutPlan,
415
534
style: Theme .of (context).textTheme.headline4,
416
535
),
417
536
subtitle: Text (
@@ -453,8 +572,8 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
453
572
TextButton (
454
573
child: Text (AppLocalizations .of (context).goToDetailPage),
455
574
onPressed: () {
456
- Navigator .of (context)
457
- . pushNamed ( WorkoutPlanScreen .routeName, arguments: _workoutPlan);
575
+ Navigator .of (context). pushNamed ( WorkoutPlanScreen .routeName,
576
+ arguments: _workoutPlan);
458
577
},
459
578
),
460
579
],
0 commit comments