@@ -2,13 +2,16 @@ import 'package:flutter/material.dart';
22import 'package:taskwarrior/app/utils/app_settings/app_settings.dart' ;
33import 'package:taskwarrior/app/utils/language/sentence_manager.dart' ;
44import 'package:taskwarrior/app/utils/taskfunctions/add_task_dialog_utils.dart' ;
5- import 'package:taskwarrior/app/utils/themes/theme_extension.dart' ;
65
76class AddTaskDatePickerInput extends StatefulWidget {
87 final Function (List <DateTime ?>)? onDateChanges;
98 final bool onlyDueDate;
9+ final List <int > allowedIndexes;
1010 const AddTaskDatePickerInput (
11- {super .key, this .onDateChanges, this .onlyDueDate = false });
11+ {super .key,
12+ this .onDateChanges,
13+ this .onlyDueDate = false ,
14+ this .allowedIndexes = const [0 , 1 , 2 , 3 ]});
1215
1316 @override
1417 _AddTaskDatePickerInputState createState () => _AddTaskDatePickerInputState ();
@@ -42,32 +45,23 @@ class _AddTaskDatePickerInputState extends State<AddTaskDatePickerInput> {
4245 child: DropdownButtonHideUnderline (
4346 child: DropdownButton <int >(
4447 value: currentIndex,
45- itemHeight: null ,
46- items: List .generate (length, (index) {
47- bool hasDate = _selectedDates[index] != null ;
48- return DropdownMenuItem <int >(
49- value: index,
50- child: Row (
51- mainAxisSize: MainAxisSize .max,
52- mainAxisAlignment: MainAxisAlignment .spaceBetween,
53- children: [
54- Text (dateLabels[index]),
55- if (hasDate)
56- const Padding (
57- padding: EdgeInsets .only (left: 12 ),
58- child: Icon (Icons .check_circle,
59- size: 14 , color: Colors .white),
60- ),
61- ],
62- ),
63- );
64- }),
48+ items: [
49+ for (int index = 0 ; index < length; index++ )
50+ if (widget.allowedIndexes
51+ .contains (index)) // Only add if allowed
52+ DropdownMenuItem <int >(
53+ value: index,
54+ child: Row (
55+ children: [
56+ Text (dateLabels[index]),
57+ if (_selectedDates[index] != null )
58+ const Icon (Icons .check_circle, size: 14 ),
59+ ],
60+ ),
61+ ),
62+ ],
6563 onChanged: (value) {
66- if (value != null ) {
67- setState (() {
68- currentIndex = value;
69- });
70- }
64+ if (value != null ) setState (() => currentIndex = value);
7165 },
7266 ),
7367 ),
@@ -106,18 +100,18 @@ class _AddTaskDatePickerInputState extends State<AddTaskDatePickerInput> {
106100 firstDate: DateTime .now (),
107101 lastDate: DateTime (2101 ),
108102 );
109-
103+
110104 // FIX: Check if date was selected before showing time picker
111105 if (picked == null ) {
112106 return ; // User canceled date picker, exit early
113107 }
114-
108+
115109 // Only show time picker if date was selected
116110 final TimeOfDay ? time = await showTimePicker (
117111 context: context,
118112 initialTime: TimeOfDay .now (),
119113 );
120-
114+
121115 // If user cancels time picker, still set the date with default time
122116 if (time == null ) {
123117 setState (() {
@@ -134,7 +128,7 @@ class _AddTaskDatePickerInputState extends State<AddTaskDatePickerInput> {
134128 }
135129 return ;
136130 }
137-
131+
138132 // Both date and time selected
139133 setState (() {
140134 _selectedDates[forIndex] =
@@ -160,4 +154,4 @@ class _AddTaskDatePickerInputState extends State<AddTaskDatePickerInput> {
160154 }
161155 return null ;
162156 }
163- }
157+ }
0 commit comments