Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 44 additions & 83 deletions lib/app/utils/add_task_dialogue/date_picker_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,6 @@ class _AddTaskDatePickerInputState extends State<AddTaskDatePickerInput> {
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) {
Expand All @@ -48,75 +32,50 @@ class _AddTaskDatePickerInputState extends State<AddTaskDatePickerInput> {

@override
Widget build(BuildContext context) {
TaskwarriorColorTheme tColors =
Theme.of(context).extension<TaskwarriorColorTheme>()!;
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<int>(
value: currentIndex,
itemHeight: null,
items: List.generate(length, (index) {
bool hasDate = _selectedDates[index] != null;
return DropdownMenuItem<int>(
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),
),
],
);
}
Expand All @@ -130,9 +89,11 @@ class _AddTaskDatePickerInputState extends State<AddTaskDatePickerInput> {
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(),
),
Expand Down