Skip to content

Commit f90609f

Browse files
committed
various dcm cleanups
1 parent 7e6c78c commit f90609f

File tree

8 files changed

+47
-51
lines changed

8 files changed

+47
-51
lines changed

lib/models/nutrition/nutritional_goals.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class NutritionalGoals {
134134

135135
@override
136136
String toString() {
137+
// ignore: avoid-nullable-interpolation
137138
return 'e: $energy, p: $protein, c: $carbohydrates, cS: $carbohydratesSugar, f: $fat, fS: $fatSaturated, fi: $fiber, s: $sodium';
138139
}
139140

lib/screens/nutritional_plan_screen.dart

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,23 @@ class NutritionalPlanScreen extends StatelessWidget {
112112
PopupMenuButton<NutritionalPlanOptions>(
113113
icon: const Icon(Icons.more_vert, color: appBarForeground),
114114
onSelected: (value) {
115-
if (value == NutritionalPlanOptions.edit) {
116-
Navigator.pushNamed(
117-
context,
118-
FormScreen.routeName,
119-
arguments: FormScreenArguments(
120-
AppLocalizations.of(context).edit,
121-
PlanForm(nutritionalPlan),
122-
hasListView: true,
123-
),
124-
);
125-
} else if (value == NutritionalPlanOptions.delete) {
126-
Provider.of<NutritionPlansProvider>(context, listen: false)
127-
.deletePlan(nutritionalPlan.id!);
128-
Navigator.of(context).pop();
115+
switch (value) {
116+
case NutritionalPlanOptions.edit:
117+
Navigator.pushNamed(
118+
context,
119+
FormScreen.routeName,
120+
arguments: FormScreenArguments(
121+
AppLocalizations.of(context).edit,
122+
PlanForm(nutritionalPlan),
123+
hasListView: true,
124+
),
125+
);
126+
break;
127+
case NutritionalPlanOptions.delete:
128+
Provider.of<NutritionPlansProvider>(context, listen: false)
129+
.deletePlan(nutritionalPlan.id!);
130+
Navigator.of(context).pop();
131+
break;
129132
}
130133
},
131134
itemBuilder: (BuildContext context) {

lib/screens/nutritional_plans_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class NutritionalPlansScreen extends StatelessWidget {
3535
appBar: EmptyAppBar(AppLocalizations.of(context).nutritionalPlans),
3636
floatingActionButton: FloatingActionButton(
3737
child: const Icon(Icons.add, color: Colors.white),
38-
onPressed: () async {
38+
onPressed: () {
3939
Navigator.pushNamed(
4040
context,
4141
FormScreen.routeName,

lib/widgets/nutrition/charts.dart

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,21 @@ import 'package:wger/models/nutrition/nutritional_plan.dart';
2626
import 'package:wger/models/nutrition/nutritional_values.dart';
2727
import 'package:wger/widgets/measurements/charts.dart';
2828

29-
class FlNutritionalPlanGoalWidget extends StatefulWidget {
30-
const FlNutritionalPlanGoalWidget({
31-
super.key,
32-
required NutritionalPlan nutritionalPlan,
33-
}) : _nutritionalPlan = nutritionalPlan;
34-
35-
final NutritionalPlan _nutritionalPlan;
36-
37-
@override
38-
State<StatefulWidget> createState() => FlNutritionalPlanGoalWidgetState();
39-
}
40-
4129
// * fl_chart doesn't support horizontal bar charts yet.
4230
// see https://github.com/imaNNeo/fl_chart/issues/113
4331
// even if it did, i doubt it would let us put text between the gauges/bars
4432
// * LinearProgressIndicator has no way to visualize going beyond 100%, or
4533
// using multiple colors to show multiple components such as surplus, deficit
4634
// * here we draw our own simple gauges that can go beyond 100%,
4735
// and support multiple segments
48-
class FlNutritionalPlanGoalWidgetState extends State<FlNutritionalPlanGoalWidget> {
36+
class FlNutritionalPlanGoalWidget extends StatelessWidget {
37+
const FlNutritionalPlanGoalWidget({
38+
super.key,
39+
required NutritionalPlan nutritionalPlan,
40+
}) : _nutritionalPlan = nutritionalPlan;
41+
42+
final NutritionalPlan _nutritionalPlan;
43+
4944
// normWidth is the width representing 100% completion
5045
// note that if val > plan, we will draw beyond this width
5146
// therefore, caller must set this width to accommodate surpluses.
@@ -91,7 +86,7 @@ class FlNutritionalPlanGoalWidgetState extends State<FlNutritionalPlanGoalWidget
9186

9287
@override
9388
Widget build(BuildContext context) {
94-
final plan = widget._nutritionalPlan;
89+
final plan = _nutritionalPlan;
9590
final goals = plan.nutritionalGoals;
9691
final today = plan.loggedNutritionalValuesToday;
9792

lib/widgets/nutrition/forms.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,12 @@ class IngredientFormState extends State<IngredientForm> {
379379
style: const TextStyle(color: Colors.red),
380380
),
381381
);
382-
} else {
383-
return const SizedBox(
384-
width: 20,
385-
height: 20,
386-
child: CircularProgressIndicator(),
387-
);
388382
}
383+
return const SizedBox(
384+
width: 20,
385+
height: 20,
386+
child: CircularProgressIndicator(),
387+
);
389388
},
390389
),
391390
],
@@ -394,7 +393,7 @@ class IngredientFormState extends State<IngredientForm> {
394393
ElevatedButton(
395394
key: const Key(SUBMIT_BUTTON_KEY_NAME),
396395
child: Text(AppLocalizations.of(context).save),
397-
onPressed: () async {
396+
onPressed: () {
398397
if (!_form.currentState!.validate()) {
399398
return;
400399
}

lib/widgets/nutrition/helpers.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void showIngredientDetails(BuildContext context, int id, {void Function()? selec
105105
builder: (context) => FutureBuilder<Ingredient>(
106106
future: Provider.of<NutritionPlansProvider>(context, listen: false).fetchIngredient(id),
107107
builder: (BuildContext context, AsyncSnapshot<Ingredient> snapshot) {
108-
return IngredientDetails(snapshot, select: select);
108+
return IngredientDetails(snapshot, onSelect: select);
109109
},
110110
),
111111
);

lib/widgets/nutrition/ingredient_dialogs.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Widget ingredientImage(String url, BuildContext context) {
2121

2222
class IngredientDetails extends StatelessWidget {
2323
final AsyncSnapshot<Ingredient> snapshot;
24-
final void Function()? select;
25-
const IngredientDetails(this.snapshot, {super.key, this.select});
24+
final void Function()? onSelect;
25+
const IngredientDetails(this.snapshot, {super.key, this.onSelect});
2626

2727
@override
2828
Widget build(BuildContext context) {
@@ -76,12 +76,12 @@ class IngredientDetails extends StatelessWidget {
7676
),
7777
),
7878
actions: [
79-
if (snapshot.hasData && select != null)
79+
if (snapshot.hasData && onSelect != null)
8080
TextButton(
8181
key: const Key('ingredient-details-continue-button'),
8282
child: Text(MaterialLocalizations.of(context).continueButtonLabel),
8383
onPressed: () {
84-
select!();
84+
onSelect!();
8585
Navigator.of(context).pop();
8686
},
8787
),
@@ -100,9 +100,14 @@ class IngredientDetails extends StatelessWidget {
100100
class IngredientScanResultDialog extends StatelessWidget {
101101
final AsyncSnapshot<Ingredient?> snapshot;
102102
final String barcode;
103-
final Function(int id, String name, num? amount) selectIngredient;
103+
final Function(int id, String name, num? amount) onSelectIngredient;
104104

105-
const IngredientScanResultDialog(this.snapshot, this.barcode, this.selectIngredient, {super.key});
105+
const IngredientScanResultDialog(
106+
this.snapshot,
107+
this.barcode,
108+
this.onSelectIngredient, {
109+
super.key,
110+
});
106111

107112
@override
108113
Widget build(BuildContext context) {
@@ -181,7 +186,7 @@ class IngredientScanResultDialog extends StatelessWidget {
181186
key: const Key('ingredient-scan-result-dialog-confirm-button'),
182187
child: Text(MaterialLocalizations.of(context).continueButtonLabel),
183188
onPressed: () {
184-
selectIngredient(ingredient!.id, ingredient.name, null);
189+
onSelectIngredient(ingredient!.id, ingredient.name, null);
185190
Navigator.of(context).pop();
186191
},
187192
),

test/nutrition/nutritional_meal_item_form_test.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import 'package:wger/widgets/nutrition/forms.dart';
2121

2222
import '../../test_data/nutritional_plans.dart';
2323
import '../fixtures/fixture_reader.dart';
24-
import '../measurements/measurement_provider_test.mocks.dart';
2524
import '../other/base_provider_test.mocks.dart';
2625
import 'nutritional_plan_form_test.mocks.dart';
2726

@@ -44,15 +43,9 @@ void main() {
4443
sodium: 0.5,
4544
);
4645

47-
late MockWgerBaseProvider mockWgerBaseProvider;
48-
4946
var mockNutrition = MockNutritionPlansProvider();
5047
final client = MockClient();
5148

52-
setUp(() {
53-
mockWgerBaseProvider = MockWgerBaseProvider();
54-
});
55-
5649
var plan1 = NutritionalPlan.empty();
5750
var meal1 = Meal();
5851

0 commit comments

Comments
 (0)