Skip to content

Commit

Permalink
Fixes setting past time
Browse files Browse the repository at this point in the history
  • Loading branch information
vkprogrammer-001 committed Jan 25, 2024
1 parent 10bb650 commit 2bb843e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions lib/widgets/add_Task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,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 @@ -226,7 +226,16 @@ 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();
}
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 2bb843e

Please sign in to comment.