From 2bb843e09c7a4697bdf93eecf064909db60c18fd Mon Sep 17 00:00:00 2001 From: vkprogrammer-001 Date: Fri, 26 Jan 2024 01:33:09 +0530 Subject: [PATCH 1/2] Fixes setting past time --- lib/widgets/add_Task.dart | 13 +++++++++++-- lib/widgets/taskdetails/dateTimePicker.dart | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/widgets/add_Task.dart b/lib/widgets/add_Task.dart index acbc0a4c..943483e9 100644 --- a/lib/widgets/add_Task.dart +++ b/lib/widgets/add_Task.dart @@ -212,7 +212,7 @@ class _AddTaskBottomSheetState extends State { }, context: context, initialTime: - TimeOfDay.fromDateTime(due ?? DateTime.now()), + TimeOfDay.now(), ); if (time != null) { var dateTime = date.add( @@ -226,7 +226,16 @@ class _AddTaskBottomSheetState extends State { hours: time.hour - dateTime.hour, ), ); - due = dateTime.toUtc(); + // Check if the selected time is in the past + if (dateTime.isBefore(DateTime.now())) { + // Show a message that past times can't be set + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text("Can't set times in the past")), + ); + } else { + // If the time is not in the past, proceed as usual + due=dateTime.toUtc(); + } NotificationService notificationService = NotificationService(); notificationService.initiliazeNotification(); diff --git a/lib/widgets/taskdetails/dateTimePicker.dart b/lib/widgets/taskdetails/dateTimePicker.dart index 61f66c6c..9a28c0a5 100644 --- a/lib/widgets/taskdetails/dateTimePicker.dart +++ b/lib/widgets/taskdetails/dateTimePicker.dart @@ -74,7 +74,7 @@ class DateTimeWidget extends StatelessWidget { if (date != null) { var time = await showTimePicker( context: context, - initialTime: TimeOfDay.fromDateTime(initialDate), + initialTime: TimeOfDay.now(), ); if (time != null) { var dateTime = date.add( @@ -88,7 +88,16 @@ class DateTimeWidget extends StatelessWidget { hours: time.hour - dateTime.hour, ), ); - return callback(dateTime.toUtc()); + // Check if the selected time is in the past + if (dateTime.isBefore(DateTime.now())) { + // Show a message that past times can't be set + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text("Can't set times in the past")), + ); + } else { + // If the time is not in the past, proceed as usual + return callback(dateTime.toUtc()); + } } } }, From 7496d5298451b9575a67f341c03a9bfa67c45e24 Mon Sep 17 00:00:00 2001 From: vkprogrammer-001 Date: Sat, 27 Jan 2024 02:31:57 +0530 Subject: [PATCH 2/2] fixes past time set --- lib/widgets/add_Task.dart | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/widgets/add_Task.dart b/lib/widgets/add_Task.dart index 943483e9..202bf7f1 100644 --- a/lib/widgets/add_Task.dart +++ b/lib/widgets/add_Task.dart @@ -212,7 +212,8 @@ class _AddTaskBottomSheetState extends State { }, context: context, initialTime: - TimeOfDay.now(), + TimeOfDay.fromDateTime(due ?? DateTime.now()), + // TimeOfDay.now(), ); if (time != null) { var dateTime = date.add( @@ -226,16 +227,17 @@ class _AddTaskBottomSheetState extends State { hours: time.hour - dateTime.hour, ), ); - // Check if the selected time is in the past - if (dateTime.isBefore(DateTime.now())) { - // Show a message that past times can't be set - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text("Can't set times in the past")), - ); - } else { - // If the time is not in the past, proceed as usual - due=dateTime.toUtc(); - } + // // Check if the selected time is in the past + // if (dateTime.isBefore(DateTime.now())) { + // // Show a message that past times can't be set + // ScaffoldMessenger.of(context).showSnackBar( + // const SnackBar(content: Text("Can't set times in the past")), + // ); + // } else { + // // If the time is not in the past, proceed as usual + // due=dateTime.toUtc(); + // } + due=dateTime.toUtc(); NotificationService notificationService = NotificationService(); notificationService.initiliazeNotification();