Skip to content

Commit ffeaad6

Browse files
committed
Use current DateTime when copying WeightEntry instead of previous.
Increment weight by 0.1 and round to one decimal place to prevent floating point accuracy (rounding) issues.
1 parent 80e33f3 commit ffeaad6

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/models/body_weight/weight_entry.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class WeightEntry {
4343
WeightEntry copyWith({int? id, int? weight, DateTime? date}) => WeightEntry(
4444
id: id,
4545
weight: weight ?? this.weight,
46-
date: date ?? this.date,
46+
date: date ?? DateTime.now(),
4747
);
4848

4949
// Boilerplate

lib/widgets/weight/forms.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class WeightForm extends StatelessWidget {
110110
icon: const FaIcon(FontAwesomeIcons.minus),
111111
onPressed: () {
112112
try {
113-
final num newValue = num.parse(weightController.text) - 0.25;
114-
weightController.text = newValue.toString();
113+
final num newValue = num.parse(weightController.text) - 0.1;
114+
weightController.text = newValue.toStringAsFixed(1);
115115
} on FormatException {}
116116
},
117117
),
@@ -125,8 +125,8 @@ class WeightForm extends StatelessWidget {
125125
icon: const FaIcon(FontAwesomeIcons.plus),
126126
onPressed: () {
127127
try {
128-
final num newValue = num.parse(weightController.text) + 0.25;
129-
weightController.text = newValue.toString();
128+
final num newValue = num.parse(weightController.text) + 0.1;
129+
weightController.text = newValue.toStringAsFixed(1);
130130
} on FormatException {}
131131
},
132132
),

0 commit comments

Comments
 (0)