diff --git a/lib/app/utils/add_task_dialogue/date_picker_input.dart b/lib/app/utils/add_task_dialogue/date_picker_input.dart index 50475052..fe1d6f13 100644 --- a/lib/app/utils/add_task_dialogue/date_picker_input.dart +++ b/lib/app/utils/add_task_dialogue/date_picker_input.dart @@ -22,22 +22,6 @@ class _AddTaskDatePickerInputState extends State { final int length = 4; int currentIndex = 0; - int getNextIndex() => (currentIndex + 1) % length; - - int getPreviousIndex() => (currentIndex - 1) % length; - - void _showNextItem() { - setState(() { - currentIndex = getNextIndex(); - }); - } - - void _showPreviousItem() { - setState(() { - currentIndex = getPreviousIndex(); - }); - } - @override void dispose() { for (var controller in _controllers) { @@ -48,75 +32,50 @@ class _AddTaskDatePickerInputState extends State { @override Widget build(BuildContext context) { - TaskwarriorColorTheme tColors = - Theme.of(context).extension()!; - bool isNextDateSelected = _selectedDates[getNextIndex()] != null; - bool isPreviousDateSelected = _selectedDates[getPreviousIndex()] != null; - String nextDateText = isNextDateSelected - ? "${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.change} ${dateLabels[getNextIndex()]} ${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.date}" - : "${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.add} ${dateLabels[getNextIndex()]} ${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.date}"; - - String prevDateText = isPreviousDateSelected - ? "${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.change} ${dateLabels[getPreviousIndex()]} ${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.date}" - : "${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.add} ${dateLabels[getPreviousIndex()]} ${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.date}"; - return Column( - mainAxisSize: MainAxisSize.min, + return Row( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - // Display the current input field - Flexible( - child: buildDatePicker(context, currentIndex), - ), - // Navigation buttons - Visibility( - visible: !widget.onlyDueDate, - child: Row( - children: [ - Expanded( - child: TextButton.icon( - onPressed: _showPreviousItem, - label: Text( - prevDateText, - style: TextStyle( - fontSize: 12, - decoration: isPreviousDateSelected - ? TextDecoration.none - : TextDecoration.underline, - decorationStyle: TextDecorationStyle.wavy, - ), - ), - icon: Icon( - Icons.arrow_back_ios_rounded, - size: 12, - color: tColors.primaryTextColor, - ), - iconAlignment: IconAlignment.start, - ), - ), - const SizedBox(width: 8), // Space between buttons - Expanded( - child: TextButton.icon( - onPressed: _showNextItem, - label: Text( - nextDateText, - style: TextStyle( - fontSize: 12, - decoration: isNextDateSelected - ? TextDecoration.none - : TextDecoration.underline, - decorationStyle: TextDecorationStyle.wavy, + // Dropdown for date type selection + if (!widget.onlyDueDate) + Container( + margin: const EdgeInsets.only(right: 8), + child: DropdownButtonHideUnderline( + child: DropdownButton( + value: currentIndex, + itemHeight: null, + items: List.generate(length, (index) { + bool hasDate = _selectedDates[index] != null; + return DropdownMenuItem( + value: index, + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text(dateLabels[index]), + if (hasDate) + const Padding( + padding: EdgeInsets.only(left: 12), + child: Icon(Icons.check_circle, + size: 14, color: Colors.white), + ), + ], ), - ), - icon: Icon( - Icons.arrow_forward_ios_rounded, - size: 12, - color: tColors.primaryTextColor, - ), - iconAlignment: IconAlignment.end, - ), + ); + }), + onChanged: (value) { + if (value != null) { + setState(() { + currentIndex = value; + }); + } + }, ), - ], + ), ), - ) + // Date picker field + Expanded( + child: buildDatePicker(context, currentIndex), + ), ], ); } @@ -130,9 +89,11 @@ class _AddTaskDatePickerInputState extends State { controller: _controllers[forIndex], decoration: InputDecoration( labelText: - '${dateLabels[forIndex]} ${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.date}', + SentenceManager(currentLanguage: AppSettings.selectedLanguage) + .sentences + .date, hintText: - '${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.select} ${dateLabels[forIndex]}', + '${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.select} ${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.date}', suffixIcon: const Icon(Icons.calendar_today), border: const OutlineInputBorder(), ),