mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-19 07:50:52 +01:00
Return a new instance when adding nutritional values
Changing the current one doesn't make sense
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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', () {
|
||||
|
||||
Reference in New Issue
Block a user