Return a new instance when adding nutritional values

Changing the current one doesn't make sense
This commit is contained in:
Roland Geider
2021-04-22 10:27:58 +02:00
parent 8787dc0582
commit 5bc1ca699d
2 changed files with 8 additions and 19 deletions

View File

@@ -56,24 +56,15 @@ class NutritionalValues {
}
NutritionalValues operator +(NutritionalValues o) {
energy += o.energy;
protein += o.protein;
carbohydrates += o.carbohydrates;
carbohydratesSugar += o.carbohydratesSugar;
fat += o.fat;
fatSaturated += o.fatSaturated;
fibres += o.fibres;
sodium += o.sodium;
return NutritionalValues.values(
this.energy,
this.protein,
this.carbohydrates,
this.carbohydratesSugar,
this.fat,
this.fatSaturated,
this.fibres,
this.sodium,
this.energy + o.energy,
this.protein + o.protein,
this.carbohydrates + o.carbohydrates,
this.carbohydratesSugar + o.carbohydratesSugar,
this.fat + o.fat,
this.fatSaturated + o.fatSaturated,
this.fibres + o.fibres,
this.sodium + o.sodium,
);
}

View File

@@ -42,8 +42,6 @@ void main() {
final values5 = values1 + values4;
final result = NutritionalValues.values(5000, 40.5, 440.5, 12.7, 51.0, 41.75, 31.3, 43.3);
expect(values5, result);
expect(values1, result);
});
test('Test the add method', () {