From 14bd37050342b95a0307e0c8eeca86d8d30d4bf0 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sat, 7 Sep 2024 19:44:50 +0300 Subject: [PATCH] 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 62a5dd87..47c8be9f 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 ee0dc429..17e620da 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 855d6f22..43874bd0 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())), ), ); },