Skip to content

Commit f7ef84a

Browse files
committed
fix: improve date handling in task addition
The time in addtask was being stored as UTC Time and datepicker using it as datetime(local) which was letting date to go in past. Which occured assertion error when date picker was being shown again. because date was in past and first date was todays.
1 parent 7a4340c commit f7ef84a

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

lib/app/modules/home/views/add_task_bottom_sheet.dart

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class AddTaskBottomSheet extends StatelessWidget {
250250
},
251251
fieldHintText: "Month/Date/Year",
252252
context: context,
253-
initialDate: homeController.due.value ?? DateTime.now(),
253+
initialDate: homeController.due.value?? DateTime.now(),
254254
firstDate: DateTime.now(),
255255
lastDate: DateTime(2037, 12, 31),
256256
);
@@ -305,7 +305,7 @@ class AddTaskBottomSheet extends StatelessWidget {
305305
),
306306
);
307307
// print(dateTime);
308-
homeController.due.value = dateTime.toUtc();
308+
homeController.due.value = dateTime;
309309

310310
// print("due value ${homeController.due}");
311311
homeController.dueString.value =
@@ -442,10 +442,31 @@ class AddTaskBottomSheet extends StatelessWidget {
442442
),
443443
onPressed: () async {
444444
// print(homeController.formKey.currentState);
445+
if(homeController.due.value!=null&&DateTime.now().isAfter(homeController.due.value!)){
446+
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
447+
content: Text(
448+
SentenceManager(
449+
currentLanguage:
450+
homeController.selectedLanguage.value)
451+
.sentences
452+
.addTaskTimeInPast,
453+
style: TextStyle(
454+
color: AppSettings.isDarkMode
455+
? TaskWarriorColors.kprimaryTextColor
456+
: TaskWarriorColors.kLightPrimaryTextColor,
457+
),
458+
),
459+
backgroundColor: AppSettings.isDarkMode
460+
? TaskWarriorColors.ksecondaryBackgroundColor
461+
: TaskWarriorColors
462+
.kLightSecondaryBackgroundColor,
463+
duration: const Duration(seconds: 2)));
464+
return;
465+
}
445466
if (homeController.formKey.currentState!.validate()) {
446467
try {
447468
var task = taskParser(homeController.namecontroller.text)
448-
.rebuild((b) => b..due = homeController.due.value)
469+
.rebuild((b) => b..due = homeController.due.value?.toUtc())
449470
.rebuild((p) => p..priority = homeController.priority.value);
450471
if (homeController.tagcontroller.text != "") {
451472
homeController.tags.add(homeController.tagcontroller.text.trim());
@@ -462,6 +483,7 @@ class AddTaskBottomSheet extends StatelessWidget {
462483
homeController.priority.value = 'M';
463484
homeController.tagcontroller.text = '';
464485
homeController.tags.value = [];
486+
homeController.due.value=null;
465487
homeController.update();
466488
// Navigator.of(context).pop();
467489
Get.back();

0 commit comments

Comments
 (0)