@@ -106,11 +106,36 @@ class _AddTaskDatePickerInputState extends State<AddTaskDatePickerInput> {
106106 firstDate: DateTime .now (),
107107 lastDate: DateTime (2101 ),
108108 );
109+
110+ // FIX: Check if date was selected before showing time picker
111+ if (picked == null ) {
112+ return ; // User canceled date picker, exit early
113+ }
114+
115+ // Only show time picker if date was selected
109116 final TimeOfDay ? time = await showTimePicker (
110117 context: context,
111118 initialTime: TimeOfDay .now (),
112119 );
113- if (picked == null || time == null ) return ;
120+
121+ // If user cancels time picker, still set the date with default time
122+ if (time == null ) {
123+ setState (() {
124+ // Set date with end-of-day time (23:59)
125+ _selectedDates[forIndex] = picked.add (
126+ const Duration (hours: 23 , minutes: 59 ),
127+ );
128+ // Update the controller text
129+ _controllers[forIndex].text =
130+ dateToStringForAddTask (_selectedDates[forIndex]! );
131+ });
132+ if (widget.onDateChanges != null ) {
133+ widget.onDateChanges !(_selectedDates);
134+ }
135+ return ;
136+ }
137+
138+ // Both date and time selected
114139 setState (() {
115140 _selectedDates[forIndex] =
116141 picked.add (Duration (hours: time.hour, minutes: time.minute));
@@ -135,4 +160,4 @@ class _AddTaskDatePickerInputState extends State<AddTaskDatePickerInput> {
135160 }
136161 return null ;
137162 }
138- }
163+ }
0 commit comments