various dcm cleanups

This commit is contained in:
Dieter Plaetinck
2024-09-18 21:40:00 +03:00
parent 7e6c78c5e3
commit f90609f147
8 changed files with 47 additions and 51 deletions

View File

@@ -134,6 +134,7 @@ class NutritionalGoals {
@override
String toString() {
// ignore: avoid-nullable-interpolation
return 'e: $energy, p: $protein, c: $carbohydrates, cS: $carbohydratesSugar, f: $fat, fS: $fatSaturated, fi: $fiber, s: $sodium';
}

View File

@@ -112,20 +112,23 @@ class NutritionalPlanScreen extends StatelessWidget {
PopupMenuButton<NutritionalPlanOptions>(
icon: const Icon(Icons.more_vert, color: appBarForeground),
onSelected: (value) {
if (value == NutritionalPlanOptions.edit) {
Navigator.pushNamed(
context,
FormScreen.routeName,
arguments: FormScreenArguments(
AppLocalizations.of(context).edit,
PlanForm(nutritionalPlan),
hasListView: true,
),
);
} else if (value == NutritionalPlanOptions.delete) {
Provider.of<NutritionPlansProvider>(context, listen: false)
.deletePlan(nutritionalPlan.id!);
Navigator.of(context).pop();
switch (value) {
case NutritionalPlanOptions.edit:
Navigator.pushNamed(
context,
FormScreen.routeName,
arguments: FormScreenArguments(
AppLocalizations.of(context).edit,
PlanForm(nutritionalPlan),
hasListView: true,
),
);
break;
case NutritionalPlanOptions.delete:
Provider.of<NutritionPlansProvider>(context, listen: false)
.deletePlan(nutritionalPlan.id!);
Navigator.of(context).pop();
break;
}
},
itemBuilder: (BuildContext context) {

View File

@@ -35,7 +35,7 @@ class NutritionalPlansScreen extends StatelessWidget {
appBar: EmptyAppBar(AppLocalizations.of(context).nutritionalPlans),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add, color: Colors.white),
onPressed: () async {
onPressed: () {
Navigator.pushNamed(
context,
FormScreen.routeName,

View File

@@ -26,18 +26,6 @@ import 'package:wger/models/nutrition/nutritional_plan.dart';
import 'package:wger/models/nutrition/nutritional_values.dart';
import 'package:wger/widgets/measurements/charts.dart';
class FlNutritionalPlanGoalWidget extends StatefulWidget {
const FlNutritionalPlanGoalWidget({
super.key,
required NutritionalPlan nutritionalPlan,
}) : _nutritionalPlan = nutritionalPlan;
final NutritionalPlan _nutritionalPlan;
@override
State<StatefulWidget> createState() => FlNutritionalPlanGoalWidgetState();
}
// * fl_chart doesn't support horizontal bar charts yet.
// see https://github.com/imaNNeo/fl_chart/issues/113
// even if it did, i doubt it would let us put text between the gauges/bars
@@ -45,7 +33,14 @@ class FlNutritionalPlanGoalWidget extends StatefulWidget {
// using multiple colors to show multiple components such as surplus, deficit
// * here we draw our own simple gauges that can go beyond 100%,
// and support multiple segments
class FlNutritionalPlanGoalWidgetState extends State<FlNutritionalPlanGoalWidget> {
class FlNutritionalPlanGoalWidget extends StatelessWidget {
const FlNutritionalPlanGoalWidget({
super.key,
required NutritionalPlan nutritionalPlan,
}) : _nutritionalPlan = nutritionalPlan;
final NutritionalPlan _nutritionalPlan;
// normWidth is the width representing 100% completion
// note that if val > plan, we will draw beyond this width
// therefore, caller must set this width to accommodate surpluses.
@@ -91,7 +86,7 @@ class FlNutritionalPlanGoalWidgetState extends State<FlNutritionalPlanGoalWidget
@override
Widget build(BuildContext context) {
final plan = widget._nutritionalPlan;
final plan = _nutritionalPlan;
final goals = plan.nutritionalGoals;
final today = plan.loggedNutritionalValuesToday;

View File

@@ -379,13 +379,12 @@ class IngredientFormState extends State<IngredientForm> {
style: const TextStyle(color: Colors.red),
),
);
} else {
return const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(),
);
}
return const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(),
);
},
),
],
@@ -394,7 +393,7 @@ class IngredientFormState extends State<IngredientForm> {
ElevatedButton(
key: const Key(SUBMIT_BUTTON_KEY_NAME),
child: Text(AppLocalizations.of(context).save),
onPressed: () async {
onPressed: () {
if (!_form.currentState!.validate()) {
return;
}

View File

@@ -105,7 +105,7 @@ void showIngredientDetails(BuildContext context, int id, {void Function()? selec
builder: (context) => FutureBuilder<Ingredient>(
future: Provider.of<NutritionPlansProvider>(context, listen: false).fetchIngredient(id),
builder: (BuildContext context, AsyncSnapshot<Ingredient> snapshot) {
return IngredientDetails(snapshot, select: select);
return IngredientDetails(snapshot, onSelect: select);
},
),
);

View File

@@ -21,8 +21,8 @@ Widget ingredientImage(String url, BuildContext context) {
class IngredientDetails extends StatelessWidget {
final AsyncSnapshot<Ingredient> snapshot;
final void Function()? select;
const IngredientDetails(this.snapshot, {super.key, this.select});
final void Function()? onSelect;
const IngredientDetails(this.snapshot, {super.key, this.onSelect});
@override
Widget build(BuildContext context) {
@@ -76,12 +76,12 @@ class IngredientDetails extends StatelessWidget {
),
),
actions: [
if (snapshot.hasData && select != null)
if (snapshot.hasData && onSelect != null)
TextButton(
key: const Key('ingredient-details-continue-button'),
child: Text(MaterialLocalizations.of(context).continueButtonLabel),
onPressed: () {
select!();
onSelect!();
Navigator.of(context).pop();
},
),
@@ -100,9 +100,14 @@ class IngredientDetails extends StatelessWidget {
class IngredientScanResultDialog extends StatelessWidget {
final AsyncSnapshot<Ingredient?> snapshot;
final String barcode;
final Function(int id, String name, num? amount) selectIngredient;
final Function(int id, String name, num? amount) onSelectIngredient;
const IngredientScanResultDialog(this.snapshot, this.barcode, this.selectIngredient, {super.key});
const IngredientScanResultDialog(
this.snapshot,
this.barcode,
this.onSelectIngredient, {
super.key,
});
@override
Widget build(BuildContext context) {
@@ -181,7 +186,7 @@ class IngredientScanResultDialog extends StatelessWidget {
key: const Key('ingredient-scan-result-dialog-confirm-button'),
child: Text(MaterialLocalizations.of(context).continueButtonLabel),
onPressed: () {
selectIngredient(ingredient!.id, ingredient.name, null);
onSelectIngredient(ingredient!.id, ingredient.name, null);
Navigator.of(context).pop();
},
),

View File

@@ -21,7 +21,6 @@ import 'package:wger/widgets/nutrition/forms.dart';
import '../../test_data/nutritional_plans.dart';
import '../fixtures/fixture_reader.dart';
import '../measurements/measurement_provider_test.mocks.dart';
import '../other/base_provider_test.mocks.dart';
import 'nutritional_plan_form_test.mocks.dart';
@@ -44,15 +43,9 @@ void main() {
sodium: 0.5,
);
late MockWgerBaseProvider mockWgerBaseProvider;
var mockNutrition = MockNutritionPlansProvider();
final client = MockClient();
setUp(() {
mockWgerBaseProvider = MockWgerBaseProvider();
});
var plan1 = NutritionalPlan.empty();
var meal1 = Meal();