diff --git a/lib/app/modules/home/views/filter_drawer_home_page.dart b/lib/app/modules/home/views/filter_drawer_home_page.dart index 085a969d..5ac7d1a5 100644 --- a/lib/app/modules/home/views/filter_drawer_home_page.dart +++ b/lib/app/modules/home/views/filter_drawer_home_page.dart @@ -53,12 +53,6 @@ class FilterDrawer extends StatelessWidget { homeController.selectedLanguage.value) .sentences .filterDrawerApplyFilters, - // style: GoogleFonts.poppins( - // fontWeight: TaskWarriorFonts.bold, - // color: (AppSettings.isDarkMode - // ? TaskWarriorColors.kprimaryTextColor - // : TaskWarriorColors.kLightPrimaryTextColor), - // fontSize: TaskWarriorFonts.fontSizeExtraLarge), style: TextStyle( fontFamily: FontFamily.poppins, fontWeight: TaskWarriorFonts.bold, @@ -72,8 +66,6 @@ class FilterDrawer extends StatelessWidget { color: Color.fromARGB(0, 48, 46, 46), ), Container( - // width: MediaQuery.of(context).size.width * 1, - // padding: const EdgeInsets.all(12), decoration: BoxDecoration( color: tileColor, borderRadius: BorderRadius.circular(8), @@ -251,13 +243,6 @@ class FilterDrawer extends StatelessWidget { homeController.selectedLanguage.value) .sentences .filterDrawerFilterTagBy, - // style: GoogleFonts.poppins( - // color: (AppSettings.isDarkMode - // ? TaskWarriorColors.kprimaryTextColor - // : TaskWarriorColors.kLightSecondaryTextColor), - // // - // fontSize: TaskWarriorFonts.fontSizeLarge), - //textAlign: TextAlign.right, style: TextStyle( fontFamily: FontFamily.poppins, fontSize: TaskWarriorFonts.fontSizeMedium, @@ -295,13 +280,10 @@ class FilterDrawer extends StatelessWidget { borderRadius: BorderRadius.circular(8), border: Border.all(color: TaskWarriorColors.borderColor), ), - //height: 30, child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - const Divider( - color: Color.fromARGB(0, 48, 46, 46), - ), + const SizedBox(height: 8), Padding( padding: const EdgeInsets.symmetric(horizontal: 0.0), child: Text( @@ -310,144 +292,200 @@ class FilterDrawer extends StatelessWidget { homeController.selectedLanguage.value) .sentences .filterDrawerSortBy, - // style: GoogleFonts.poppins( - // color: (AppSettings.isDarkMode - // ? TaskWarriorColors.kprimaryTextColor - // : TaskWarriorColors.kLightPrimaryTextColor), - // fontSize: TaskWarriorFonts.fontSizeLarge), - // textAlign: TextAlign.right, style: TextStyle( fontFamily: FontFamily.poppins, fontSize: TaskWarriorFonts.fontSizeMedium, color: tColors.primaryTextColor, )), ), - const Divider( - color: Color.fromARGB(0, 48, 46, 46), - ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 8.0), - child: Wrap( - spacing: 8, - runSpacing: 4, + const SizedBox(height: 12), + // Dropdown and toggle switch row + Obx(() { + final sortOptions = [ + SentenceManager( + currentLanguage: + homeController.selectedLanguage.value) + .sentences + .filterDrawerCreated, + SentenceManager( + currentLanguage: + homeController.selectedLanguage.value) + .sentences + .filterDrawerModified, + SentenceManager( + currentLanguage: + homeController.selectedLanguage.value) + .sentences + .filterDrawerStartTime, + SentenceManager( + currentLanguage: + homeController.selectedLanguage.value) + .sentences + .filterDrawerDueTill, + SentenceManager( + currentLanguage: + homeController.selectedLanguage.value) + .sentences + .filterDrawerPriority, + SentenceManager( + currentLanguage: + homeController.selectedLanguage.value) + .sentences + .filterDrawerProject, + SentenceManager( + currentLanguage: + homeController.selectedLanguage.value) + .sentences + .filterDrawerTags, + SentenceManager( + currentLanguage: + homeController.selectedLanguage.value) + .sentences + .filterDrawerUrgency, + ]; + + // Extract current sort category and order from selectedSort + String currentSort = homeController.selectedSort.value; + String? selectedCategory; + bool isAscending = false; + + if (currentSort.isNotEmpty) { + if (currentSort.endsWith('+')) { + selectedCategory = + currentSort.substring(0, currentSort.length - 1); + isAscending = true; + } else if (currentSort.endsWith('-')) { + selectedCategory = + currentSort.substring(0, currentSort.length - 1); + isAscending = false; + } else { + selectedCategory = currentSort; + } + } + + // Validate selectedCategory is in sortOptions + if (selectedCategory != null && + !sortOptions.contains(selectedCategory)) { + selectedCategory = null; + } + + return Row( children: [ - for (var sort in [ - SentenceManager( - currentLanguage: - homeController.selectedLanguage.value) - .sentences - .filterDrawerCreated, - SentenceManager( - currentLanguage: - homeController.selectedLanguage.value) - .sentences - .filterDrawerModified, - SentenceManager( - currentLanguage: - homeController.selectedLanguage.value) - .sentences - .filterDrawerStartTime, - SentenceManager( - currentLanguage: - homeController.selectedLanguage.value) - .sentences - .filterDrawerDueTill, - SentenceManager( - currentLanguage: - homeController.selectedLanguage.value) - .sentences - .filterDrawerPriority, - SentenceManager( - currentLanguage: - homeController.selectedLanguage.value) - .sentences - .filterDrawerProject, - SentenceManager( - currentLanguage: - homeController.selectedLanguage.value) - .sentences - .filterDrawerTags, - SentenceManager( - currentLanguage: - homeController.selectedLanguage.value) - .sentences - .filterDrawerUrgency, - ]) - Obx( - () => ChoiceChip( - label: (homeController.selectedSort.value - .startsWith(sort)) - ? Text( - homeController.selectedSort.value, - ) - : Text(sort), - selected: false, - onSelected: (_) { - if (homeController.selectedSort == '$sort+') { - homeController.selectSort('$sort-'); - } else if (homeController.selectedSort == - '$sort-') { - homeController.selectSort(sort); - } else { - homeController.selectSort('$sort+'); - } - }, - // labelStyle: GoogleFonts.poppins( - // color: AppSettings.isDarkMode - // ? TaskWarriorColors.black - // : TaskWarriorColors.white), - // backgroundColor: AppSettings.isDarkMode - // ? TaskWarriorColors - // .kLightSecondaryBackgroundColor - // : TaskWarriorColors.ksecondaryBackgroundColor, + // Dropdown + Expanded( + child: Container( + padding: + const EdgeInsets.symmetric(horizontal: 12.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8), + border: Border.all( + color: TaskWarriorColors.borderColor), ), - ) + child: DropdownButtonHideUnderline( + child: DropdownButton( + isExpanded: true, + value: selectedCategory, + hint: Text( + SentenceManager( + currentLanguage: homeController + .selectedLanguage.value) + .sentences + .filterDrawerSortBy, + style: TextStyle( + fontFamily: FontFamily.poppins, + fontSize: TaskWarriorFonts.fontSizeSmall, + color: tColors.primaryTextColor, + ), + ), + dropdownColor: tileColor, + style: TextStyle( + fontFamily: FontFamily.poppins, + fontSize: TaskWarriorFonts.fontSizeSmall, + color: tColors.primaryTextColor, + ), + items: sortOptions.map((String option) { + return DropdownMenuItem( + value: option, + child: Text(option), + ); + }).toList(), + onChanged: (String? newValue) { + if (newValue != null) { + // Default to ascending when selecting a new category + homeController.selectSort('$newValue+'); + } + }, + ), + ), + ), + ), + const SizedBox(width: 12), + // Toggle switch with + and - labels + Row( + children: [ + Text( + '+', + style: TextStyle( + fontFamily: FontFamily.poppins, + fontSize: TaskWarriorFonts.fontSizeMedium, + fontWeight: FontWeight.bold, + color: tColors.primaryTextColor, + ), + ), + Switch( + value: !isAscending, + onChanged: selectedCategory != null + ? (bool value) { + if (value) { + // Switch to descending (-) + homeController + .selectSort('$selectedCategory-'); + } else { + // Switch to ascending (+) + homeController + .selectSort('$selectedCategory+'); + } + } + : null, + ), + Text( + '-', + style: TextStyle( + fontFamily: FontFamily.poppins, + fontSize: TaskWarriorFonts.fontSizeMedium, + fontWeight: FontWeight.bold, + color: tColors.primaryTextColor, + ), + ), + ], + ), ], + ); + }), + const SizedBox(height: 12), + // Clear sort button + TextButton.icon( + onPressed: () { + homeController.selectSort('urgency+'); + }, + icon: Icon( + Icons.clear, + size: 18, + color: tColors.primaryTextColor, ), + label: Text( + SentenceManager( + currentLanguage: + homeController.selectedLanguage.value) + .sentences + .filterDrawerResetSort, + style: TextStyle( + fontFamily: FontFamily.poppins, + fontSize: TaskWarriorFonts.fontSizeMedium, + color: tColors.primaryTextColor, + )), ), - const Divider( - color: Color.fromARGB(0, 48, 46, 46), - ), - Container( - width: 200, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - // color: AppSettings.isDarkMode - // ? TaskWarriorColors.kLightSecondaryBackgroundColor - // : TaskWarriorColors.ksecondaryBackgroundColor, - ), - child: TextButton( - onPressed: () { - if (homeController.selectedSort.value.endsWith('+') || - homeController.selectedSort.value.endsWith('-')) { - homeController.selectSort( - homeController.selectedSort.value.substring( - 0, - homeController.selectedSort.value.length - - 1)); - } - }, - child: Text( - SentenceManager( - currentLanguage: - homeController.selectedLanguage.value) - .sentences - .filterDrawerResetSort, - // style: GoogleFonts.poppins( - // fontSize: TaskWarriorFonts.fontSizeMedium, - // color: AppSettings.isDarkMode - // ? TaskWarriorColors.kLightSecondaryTextColor - // : TaskWarriorColors.ksecondaryTextColor), - style: TextStyle( - fontFamily: FontFamily.poppins, - fontSize: TaskWarriorFonts.fontSizeMedium, - color: tColors.primaryTextColor, - )), - ), - ), - const Divider( - color: Color.fromARGB(0, 48, 46, 46), - ), + const SizedBox(height: 8), ], ), )