Skip to content

Commit

Permalink
Merge pull request #250 from vkprogrammer-001/setting_past_time
Browse files Browse the repository at this point in the history
Fixes setting past time
  • Loading branch information
Pavel401 authored Jan 27, 2024
2 parents 707615d + 7496d52 commit 2ba38ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
13 changes: 12 additions & 1 deletion lib/widgets/add_Task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class _AddTaskBottomSheetState extends State<AddTaskBottomSheet> {
context: context,
initialTime:
TimeOfDay.fromDateTime(due ?? DateTime.now()),
// TimeOfDay.now(),
);
if (time != null) {
var dateTime = date.add(
Expand All @@ -223,7 +224,17 @@ class _AddTaskBottomSheetState extends State<AddTaskBottomSheet> {
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();
// }
due=dateTime.toUtc();
NotificationService notificationService =
NotificationService();
notificationService.initiliazeNotification();
Expand Down
13 changes: 11 additions & 2 deletions lib/widgets/taskdetails/dateTimePicker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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());
}
}
}
},
Expand Down

0 comments on commit 2ba38ac

Please sign in to comment.