@@ -42,7 +42,8 @@ class MealForm extends StatelessWidget {
42
42
final _nameController = TextEditingController ();
43
43
44
44
MealForm (this ._planId, [meal]) {
45
- _meal = meal ?? Meal (plan: _planId, time: TimeOfDay .fromDateTime (DateTime .now ()));
45
+ _meal = meal ??
46
+ Meal (plan: _planId, time: TimeOfDay .fromDateTime (DateTime .now ()));
46
47
_timeController.text = timeToString (_meal.time)! ;
47
48
_nameController.text = _meal.name;
48
49
}
@@ -57,7 +58,8 @@ class MealForm extends StatelessWidget {
57
58
children: [
58
59
TextFormField (
59
60
key: const Key ('field-time' ),
60
- decoration: InputDecoration (labelText: AppLocalizations .of (context).time),
61
+ decoration:
62
+ InputDecoration (labelText: AppLocalizations .of (context).time),
61
63
controller: _timeController,
62
64
onTap: () async {
63
65
// Stop keyboard from appearing
@@ -79,7 +81,8 @@ class MealForm extends StatelessWidget {
79
81
TextFormField (
80
82
maxLength: 25 ,
81
83
key: const Key ('field-name' ),
82
- decoration: InputDecoration (labelText: AppLocalizations .of (context).name),
84
+ decoration:
85
+ InputDecoration (labelText: AppLocalizations .of (context).name),
83
86
controller: _nameController,
84
87
onSaved: (newValue) {
85
88
_meal.name = newValue as String ;
@@ -125,7 +128,8 @@ Widget MealItemForm(
125
128
recent: recent.map ((e) => Log .fromMealItem (e, 0 , e.mealId)).toList (),
126
129
onSave: (BuildContext context, MealItem mealItem, DateTime ? dt) {
127
130
mealItem.mealId = meal.id! ;
128
- Provider .of <NutritionPlansProvider >(context, listen: false ).addMealItem (mealItem, meal);
131
+ Provider .of <NutritionPlansProvider >(context, listen: false )
132
+ .addMealItem (mealItem, meal);
129
133
},
130
134
barcode: barcode ?? '' ,
131
135
test: test ?? false ,
@@ -235,9 +239,11 @@ class IngredientFormState extends State<IngredientForm> {
235
239
Widget build (BuildContext context) {
236
240
final String unit = AppLocalizations .of (context).g;
237
241
final queryLower = _searchQuery.toLowerCase ();
238
- final suggestions =
239
- widget.recent.where ((e) => e.ingredient.name.toLowerCase ().contains (queryLower)).toList ();
240
- final numberFormat = NumberFormat .decimalPattern (Localizations .localeOf (context).toString ());
242
+ final suggestions = widget.recent
243
+ .where ((e) => e.ingredient.name.toLowerCase ().contains (queryLower))
244
+ .toList ();
245
+ final numberFormat =
246
+ NumberFormat .decimalPattern (Localizations .localeOf (context).toString ());
241
247
242
248
return Container (
243
249
margin: const EdgeInsets .all (20 ),
@@ -344,7 +350,8 @@ class IngredientFormState extends State<IngredientForm> {
344
350
),
345
351
],
346
352
),
347
- if (ingredientIdController.text.isNotEmpty && _amountController.text.isNotEmpty)
353
+ if (ingredientIdController.text.isNotEmpty &&
354
+ _amountController.text.isNotEmpty)
348
355
Padding (
349
356
padding: const EdgeInsets .all (8.0 ),
350
357
child: Column (
@@ -395,7 +402,8 @@ class IngredientFormState extends State<IngredientForm> {
395
402
return ;
396
403
}
397
404
_form.currentState! .save ();
398
- _mealItem.ingredientId = int .parse (_ingredientIdController.text);
405
+ _mealItem.ingredientId =
406
+ int .parse (_ingredientIdController.text);
399
407
400
408
var date = DateTime .parse (_dateController.text);
401
409
final tod = stringToTime (_timeController.text);
@@ -508,6 +516,8 @@ class _PlanFormState extends State<PlanForm> {
508
516
GoalType _goalType = GoalType .meals;
509
517
510
518
final _descriptionController = TextEditingController ();
519
+ final _startDateController = TextEditingController ();
520
+ final _endDateController = TextEditingController ();
511
521
final TextEditingController colorController = TextEditingController ();
512
522
513
523
GoalType ? selectedGoal;
@@ -518,6 +528,12 @@ class _PlanFormState extends State<PlanForm> {
518
528
519
529
_onlyLogging = widget._plan.onlyLogging;
520
530
_descriptionController.text = widget._plan.description;
531
+ _startDateController.text =
532
+ '${widget ._plan .startDate .year }-${widget ._plan .startDate .month .toString ().padLeft (2 , '0' )}-${widget ._plan .startDate .day .toString ().padLeft (2 , '0' )}' ;
533
+ if (widget._plan.endDate != null ) {
534
+ _endDateController.text =
535
+ '${widget ._plan .endDate !.year }-${widget ._plan .endDate !.month .toString ().padLeft (2 , '0' )}-${widget ._plan .endDate !.day .toString ().padLeft (2 , '0' )}' ;
536
+ }
521
537
if (widget._plan.hasAnyAdvancedGoals) {
522
538
_goalType = GoalType .advanced;
523
539
} else if (widget._plan.hasAnyGoals) {
@@ -530,6 +546,8 @@ class _PlanFormState extends State<PlanForm> {
530
546
@override
531
547
void dispose () {
532
548
_descriptionController.dispose ();
549
+ _startDateController.dispose ();
550
+ _endDateController.dispose ();
533
551
colorController.dispose ();
534
552
super .dispose ();
535
553
}
@@ -551,6 +569,66 @@ class _PlanFormState extends State<PlanForm> {
551
569
widget._plan.description = newValue! ;
552
570
},
553
571
),
572
+ // Start Date
573
+ TextFormField (
574
+ key: const Key ('field-start-date' ),
575
+ decoration: InputDecoration (
576
+ labelText: AppLocalizations .of (context).start,
577
+ hintText: 'YYYY-MM-DD' ,
578
+ ),
579
+ controller: _startDateController,
580
+ readOnly: true ,
581
+ onTap: () async {
582
+ // Stop keyboard from appearing
583
+ FocusScope .of (context).requestFocus (FocusNode ());
584
+
585
+ // Open date picker
586
+ final pickedDate = await showDatePicker (
587
+ context: context,
588
+ initialDate: widget._plan.startDate,
589
+ firstDate: DateTime (2000 ),
590
+ lastDate: DateTime (2100 ),
591
+ );
592
+
593
+ if (pickedDate != null ) {
594
+ setState (() {
595
+ _startDateController.text =
596
+ '${pickedDate .year }-${pickedDate .month .toString ().padLeft (2 , '0' )}-${pickedDate .day .toString ().padLeft (2 , '0' )}' ;
597
+ widget._plan.startDate = pickedDate;
598
+ });
599
+ }
600
+ },
601
+ ),
602
+ // End Date
603
+ TextFormField (
604
+ key: const Key ('field-end-date' ),
605
+ decoration: InputDecoration (
606
+ labelText: AppLocalizations .of (context).endDate,
607
+ hintText: 'YYYY-MM-DD' ,
608
+ ),
609
+ controller: _endDateController,
610
+ readOnly: true ,
611
+ onTap: () async {
612
+ // Stop keyboard from appearing
613
+ FocusScope .of (context).requestFocus (FocusNode ());
614
+
615
+ // Open date picker
616
+ final pickedDate = await showDatePicker (
617
+ context: context,
618
+ initialDate: widget._plan.endDate,
619
+ firstDate: DateTime (2000 ),
620
+ lastDate: DateTime (2100 ),
621
+ );
622
+
623
+ if (pickedDate != null ) {
624
+ setState (() {
625
+ _endDateController.text =
626
+ '${pickedDate .year }-${pickedDate .month .toString ().padLeft (2 , '0' )}-${pickedDate .day .toString ().padLeft (2 , '0' )}' ;
627
+ widget._plan.endDate = pickedDate;
628
+ });
629
+ }
630
+ },
631
+ ),
554
632
SwitchListTile (
555
633
title: Text (AppLocalizations .of (context).onlyLogging),
556
634
subtitle: Text (AppLocalizations .of (context).onlyLoggingHelpText),
@@ -626,7 +704,8 @@ class _PlanFormState extends State<PlanForm> {
626
704
val: widget._plan.goalCarbohydrates? .toString (),
627
705
label: AppLocalizations .of (context).goalCarbohydrates,
628
706
suffix: AppLocalizations .of (context).g,
629
- onSave: (double value) => widget._plan.goalCarbohydrates = value,
707
+ onSave: (double value) =>
708
+ widget._plan.goalCarbohydrates = value,
630
709
key: const Key ('field-goal-carbohydrates' ),
631
710
),
632
711
GoalMacros (
@@ -706,7 +785,8 @@ class GoalMacros extends StatelessWidget {
706
785
707
786
@override
708
787
Widget build (BuildContext context) {
709
- final numberFormat = NumberFormat .decimalPattern (Localizations .localeOf (context).toString ());
788
+ final numberFormat =
789
+ NumberFormat .decimalPattern (Localizations .localeOf (context).toString ());
710
790
711
791
return TextFormField (
712
792
initialValue: val ?? '' ,
0 commit comments