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()); + } } } },