From ffeaad6f0c256d5c5cfcae8dfdaa9e34beec588c Mon Sep 17 00:00:00 2001 From: dan <64416644+brittle-bones@users.noreply.github.com> Date: Thu, 5 Sep 2024 01:16:31 +0100 Subject: [PATCH 1/4] 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. --- lib/models/body_weight/weight_entry.dart | 2 +- lib/widgets/weight/forms.dart | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/models/body_weight/weight_entry.dart b/lib/models/body_weight/weight_entry.dart index 47c8be9fa..62a5dd87d 100644 --- a/lib/models/body_weight/weight_entry.dart +++ b/lib/models/body_weight/weight_entry.dart @@ -43,7 +43,7 @@ class WeightEntry { WeightEntry copyWith({int? id, int? weight, DateTime? date}) => WeightEntry( id: id, weight: weight ?? this.weight, - date: date ?? this.date, + date: date ?? DateTime.now(), ); // Boilerplate diff --git a/lib/widgets/weight/forms.dart b/lib/widgets/weight/forms.dart index 1f47f0515..343a0cf87 100644 --- a/lib/widgets/weight/forms.dart +++ b/lib/widgets/weight/forms.dart @@ -110,8 +110,8 @@ class WeightForm extends StatelessWidget { icon: const FaIcon(FontAwesomeIcons.minus), onPressed: () { try { - final num newValue = num.parse(weightController.text) - 0.25; - weightController.text = newValue.toString(); + final num newValue = num.parse(weightController.text) - 0.1; + weightController.text = newValue.toStringAsFixed(1); } on FormatException {} }, ), @@ -125,8 +125,8 @@ class WeightForm extends StatelessWidget { icon: const FaIcon(FontAwesomeIcons.plus), onPressed: () { try { - final num newValue = num.parse(weightController.text) + 0.25; - weightController.text = newValue.toString(); + final num newValue = num.parse(weightController.text) + 0.1; + weightController.text = newValue.toStringAsFixed(1); } on FormatException {} }, ), From eaef5513b9df868ce71f5114be397665f28e22f6 Mon Sep 17 00:00:00 2001 From: dan <64416644+brittle-bones@users.noreply.github.com> Date: Thu, 5 Sep 2024 20:55:06 +0100 Subject: [PATCH 2/4] Add to authors list. Removed whitespace. --- AUTHORS.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index 2478f3908..ee664bf4b 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -29,11 +29,12 @@ - Bassam Mutairi - - Dieter Plaetinck - - Dennis van Peer - +- sizzlesloth - ## Translators - Saudi Arabian - - Hanaa Allohibi + - Hanaa Allohibi - German @@ -66,7 +67,7 @@ - Norwegian Bokmål - Allan Nordhøy (98) - + - Japanese - Kosei TANAKA (97) @@ -76,5 +77,5 @@ - Nenza Nurfirmansyah (73) - Croatian - + - Sandi Milohaic From 14bd37050342b95a0307e0c8eeca86d8d30d4bf0 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 7 Sep 2024 19:44:50 +0300 Subject: [PATCH 3/4] solve the date fix in a cleaner way --- lib/models/body_weight/weight_entry.dart | 2 +- lib/screens/weight_screen.dart | 2 +- lib/widgets/dashboard/widgets.dart | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/models/body_weight/weight_entry.dart b/lib/models/body_weight/weight_entry.dart index 62a5dd87d..47c8be9fa 100644 --- a/lib/models/body_weight/weight_entry.dart +++ b/lib/models/body_weight/weight_entry.dart @@ -43,7 +43,7 @@ class WeightEntry { WeightEntry copyWith({int? id, int? weight, DateTime? date}) => WeightEntry( id: id, weight: weight ?? this.weight, - date: date ?? DateTime.now(), + date: date ?? this.date, ); // Boilerplate diff --git a/lib/screens/weight_screen.dart b/lib/screens/weight_screen.dart index ee0dc429f..17e620dac 100644 --- a/lib/screens/weight_screen.dart +++ b/lib/screens/weight_screen.dart @@ -43,7 +43,7 @@ class WeightScreen extends StatelessWidget { FormScreen.routeName, arguments: FormScreenArguments( AppLocalizations.of(context).newEntry, - WeightForm(lastWeightEntry?.copyWith(id: null)), + WeightForm(lastWeightEntry?.copyWith(id: null, date: DateTime.now())), ), ); }, diff --git a/lib/widgets/dashboard/widgets.dart b/lib/widgets/dashboard/widgets.dart index 855d6f227..43874bd0c 100644 --- a/lib/widgets/dashboard/widgets.dart +++ b/lib/widgets/dashboard/widgets.dart @@ -209,7 +209,9 @@ class _DashboardWeightWidgetState extends State { FormScreen.routeName, arguments: FormScreenArguments( AppLocalizations.of(context).newEntry, - WeightForm(weightProvider.getNewestEntry()?.copyWith(id: null)), + WeightForm(weightProvider + .getNewestEntry() + ?.copyWith(id: null, date: DateTime.now())), ), ); }, From a64a50f42544c480250cd3cd9a5a1884216af8b4 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 7 Sep 2024 19:51:29 +0300 Subject: [PATCH 4/4] fix tests --- test/weight/weight_form_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/weight/weight_form_test.dart b/test/weight/weight_form_test.dart index e1158da38..e84028694 100644 --- a/test/weight/weight_form_test.dart +++ b/test/weight/weight_form_test.dart @@ -52,10 +52,10 @@ void main() { expect(find.text('79'), findsOneWidget); await tester.tap(find.byKey(const Key('quickMinusSmall'))); - expect(find.text('78.75'), findsOneWidget); + expect(find.text('78.9'), findsOneWidget); await tester.tap(find.byKey(const Key('quickPlus'))); - expect(find.text('79.75'), findsOneWidget); + expect(find.text('79.9'), findsOneWidget); await tester.tap(find.byKey(const Key('quickPlusSmall'))); expect(find.text('80.0'), findsOneWidget);