From 77fe4bc14afa5b2b3e13285afe83d18341d1406e Mon Sep 17 00:00:00 2001 From: Soumyajyoti Date: Sun, 19 Jan 2025 15:36:27 +0530 Subject: [PATCH] Fixes and Enhancements in the Navigation Bar --- .../modules/home/views/home_page_body.dart | 232 ++++++----- lib/app/modules/home/views/nav_drawer.dart | 376 ++++++++++-------- 2 files changed, 353 insertions(+), 255 deletions(-) diff --git a/lib/app/modules/home/views/home_page_body.dart b/lib/app/modules/home/views/home_page_body.dart index 5f1a370..f6ac986 100644 --- a/lib/app/modules/home/views/home_page_body.dart +++ b/lib/app/modules/home/views/home_page_body.dart @@ -1,14 +1,11 @@ import 'package:double_back_to_close_app/double_back_to_close_app.dart'; import 'package:flutter/material.dart'; - import 'package:get/get.dart'; import 'package:taskwarrior/app/modules/home/views/show_tasks.dart'; - import 'package:taskwarrior/app/modules/home/views/tasks_builder.dart'; import 'package:taskwarrior/app/utils/constants/palette.dart'; import 'package:taskwarrior/app/utils/constants/taskwarrior_colors.dart'; import 'package:taskwarrior/app/utils/app_settings/app_settings.dart'; - import '../controllers/home_controller.dart'; class HomePageBody extends StatelessWidget { @@ -19,106 +16,145 @@ class HomePageBody extends StatelessWidget { Widget build(BuildContext context) { controller.initInAppTour(); controller.showInAppTour(context); - return DoubleBackToCloseApp( - snackBar: const SnackBar(content: Text('Tap back again to exit')), - child: Container( - color: AppSettings.isDarkMode - ? Palette.kToDark.shade200 - : TaskWarriorColors.white, - child: Padding( - padding: const EdgeInsets.only(left: 8.0, right: 8.0), - child: Obx( - () => Column( - children: [ - if (controller.searchVisible.value) - Container( - margin: const EdgeInsets.symmetric( - horizontal: 10, vertical: 10), - child: SearchBar( - backgroundColor: WidgetStateProperty.all( - (TaskWarriorColors.kLightPrimaryBackgroundColor)), - surfaceTintColor: WidgetStateProperty.all( - (TaskWarriorColors.kLightPrimaryBackgroundColor)), - controller: controller.searchController, - // shape:, - onChanged: (value) { - controller.search(value); - }, - - shape: WidgetStateProperty.resolveWith( - (Set states) { - if (states.contains(WidgetState.focused)) { - return RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12.0), - side: BorderSide( - color: TaskWarriorColors.black, - width: 2.0, - ), - ); - } else { - return RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12.0), - side: BorderSide( - color: TaskWarriorColors.black, - width: 1.5, - ), - ); - } - }, + return Scaffold( + drawer: Drawer( + // Add your drawer content here + child: ListView( + padding: EdgeInsets.zero, + children: const [ + DrawerHeader( + decoration: BoxDecoration( + color: Colors.blue, + ), + child: Text( + 'Drawer Header', + style: TextStyle( + color: Colors.white, + fontSize: 24, + ), + ), + ), + ListTile( + leading: Icon(Icons.message), + title: Text('Messages'), + ), + ListTile( + leading: Icon(Icons.account_circle), + title: Text('Profile'), + ), + ListTile( + leading: Icon(Icons.settings), + title: Text('Settings'), + ), + ], + ), + ), + body: GestureDetector( + onHorizontalDragEnd: (details) { + if (details.primaryVelocity! > 0) { + Scaffold.of(context).openDrawer(); + } + }, + child: DoubleBackToCloseApp( + snackBar: const SnackBar(content: Text('Tap back again to exit')), + child: Container( + color: AppSettings.isDarkMode + ? Palette.kToDark.shade200 + : TaskWarriorColors.white, + child: Padding( + padding: const EdgeInsets.only(left: 8.0, right: 8.0), + child: Obx( + () => Column( + children: [ + if (controller.searchVisible.value) + Container( + margin: const EdgeInsets.symmetric( + horizontal: 10, vertical: 10), + child: SearchBar( + backgroundColor: WidgetStateProperty.all( + (TaskWarriorColors.kLightPrimaryBackgroundColor)), + surfaceTintColor: WidgetStateProperty.all( + (TaskWarriorColors.kLightPrimaryBackgroundColor)), + controller: controller.searchController, + onChanged: (value) { + controller.search(value); + }, + shape: + WidgetStateProperty.resolveWith( + (Set states) { + if (states.contains(WidgetState.focused)) { + return RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12.0), + side: BorderSide( + color: TaskWarriorColors.black, + width: 2.0, + ), + ); + } else { + return RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12.0), + side: BorderSide( + color: TaskWarriorColors.black, + width: 1.5, + ), + ); + } + }, + ), + leading: const Icon(Icons.search_rounded), + trailing: [ + (controller.searchController.text.isNotEmpty) + ? IconButton( + key: GlobalKey(), + icon: Icon(Icons.cancel, + color: TaskWarriorColors.black), + onPressed: () { + controller.searchController.clear(); + controller.search( + controller.searchController.text); + }, + ) + : const SizedBox( + width: 0, + height: 0, + ) + ], + hintText: 'Search', + ), ), - leading: const Icon(Icons.search_rounded), - trailing: [ - (controller.searchController.text.isNotEmpty) - ? IconButton( - key: GlobalKey(), - icon: Icon(Icons.cancel, - color: TaskWarriorColors.black), - onPressed: () { - controller.searchController.clear(); - controller - .search(controller.searchController.text); - }, - ) - : const SizedBox( - width: 0, - height: 0, - ) - ], - - hintText: 'Search', - ), - ), - Visibility( - visible: !controller.taskchampion.value, - child: Expanded( - child: Scrollbar( - child: Obx( - () => TasksBuilder( - // darkmode: AppSettings.isDarkMode, - useDelayTask: controller.useDelayTask.value, - taskData: controller.searchedTasks, - pendingFilter: controller.pendingFilter.value, - waitingFilter: controller.waitingFilter.value, - searchVisible: controller.searchVisible.value, - selectedLanguage: controller.selectedLanguage.value, - scrollController: controller.scrollController, - showbtn: controller.showbtn.value, + Visibility( + visible: !controller.taskchampion.value, + child: Expanded( + child: Scrollbar( + child: Obx( + () => TasksBuilder( + useDelayTask: controller.useDelayTask.value, + taskData: controller.searchedTasks, + pendingFilter: controller.pendingFilter.value, + waitingFilter: controller.waitingFilter.value, + searchVisible: controller.searchVisible.value, + selectedLanguage: + controller.selectedLanguage.value, + scrollController: controller.scrollController, + showbtn: controller.showbtn.value, + ), + ), ), ), ), - ), + Visibility( + visible: controller.taskchampion.value, + child: Expanded( + child: Scrollbar( + child: TaskViewBuilder( + pendingFilter: controller.pendingFilter.value, + selectedSort: controller.selectedSort.value, + project: controller.projectFilter.value, + ), + ))) + ], ), - Visibility( - visible: controller.taskchampion.value, - child: Expanded( - child: Scrollbar( - child: TaskViewBuilder( - pendingFilter: controller.pendingFilter.value, - selectedSort: controller.selectedSort.value, - project: controller.projectFilter.value, - ), - ))) - ], + ), ), ), ), diff --git a/lib/app/modules/home/views/nav_drawer.dart b/lib/app/modules/home/views/nav_drawer.dart index 0a3d36d..96c53ac 100644 --- a/lib/app/modules/home/views/nav_drawer.dart +++ b/lib/app/modules/home/views/nav_drawer.dart @@ -24,76 +24,87 @@ class NavDrawer extends StatelessWidget { backgroundColor: AppSettings.isDarkMode ? TaskWarriorColors.kprimaryBackgroundColor : TaskWarriorColors.kLightPrimaryBackgroundColor, - surfaceTintColor: AppSettings.isDarkMode - ? TaskWarriorColors.kprimaryBackgroundColor - : TaskWarriorColors.kLightPrimaryBackgroundColor, child: Container( color: AppSettings.isDarkMode ? TaskWarriorColors.kprimaryBackgroundColor : TaskWarriorColors.kLightPrimaryBackgroundColor, - child: ListView( - padding: EdgeInsets.zero, + child: Column( children: [ - Container( + _buildHeader(context), + Expanded(child: _buildMenuItems(context)), + _buildExitButton(context), + ], + ), + ), + ); + } + + Widget _buildHeader(BuildContext context) { + return Container( + color: AppSettings.isDarkMode + ? TaskWarriorColors.kprimaryBackgroundColor + : TaskWarriorColors.kLightPrimaryBackgroundColor, + padding: const EdgeInsets.only(top: 50, left: 15, right: 10), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + SentenceManager( + currentLanguage: homeController.selectedLanguage.value) + .sentences + .homePageMenu, + style: TextStyle( + fontSize: TaskWarriorFonts.fontSizeExtraLarge, + fontWeight: TaskWarriorFonts.bold, color: AppSettings.isDarkMode - ? TaskWarriorColors.kprimaryBackgroundColor - : TaskWarriorColors.kLightPrimaryBackgroundColor, - padding: const EdgeInsets.only(top: 50, left: 15, right: 10), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - SentenceManager( - currentLanguage: - homeController.selectedLanguage.value) - .sentences - .homePageMenu, - style: TextStyle( - fontSize: TaskWarriorFonts.fontSizeExtraLarge, - fontWeight: TaskWarriorFonts.bold, - color: AppSettings.isDarkMode - ? TaskWarriorColors.white - : TaskWarriorColors.black, - ), - ), - Padding( - padding: const EdgeInsets.only(right: 10), - child: ThemeSwitcherClipper( - isDarkMode: AppSettings.isDarkMode, - onTap: (bool newMode) async { - AppSettings.isDarkMode = newMode; - await SelectedTheme.saveMode(AppSettings.isDarkMode); - // Get.back(); - homeController.initLanguageAndDarkMode(); - }, - child: Icon( - AppSettings.isDarkMode - ? Icons.dark_mode - : Icons.light_mode, - color: AppSettings.isDarkMode - ? TaskWarriorColors.white - : TaskWarriorColors.black, - size: 15, - ), - ), - ), - ], - ), + ? TaskWarriorColors.white + : TaskWarriorColors.black, ), - Container( - color: AppSettings.isDarkMode - ? TaskWarriorColors.kprimaryBackgroundColor - : TaskWarriorColors.kLightPrimaryBackgroundColor, - height: Get.height * 0.03, + ), + Padding( + padding: const EdgeInsets.only(right: 10), + child: AnimatedSwitcher( + duration: const Duration(milliseconds: 300), + transitionBuilder: (Widget child, Animation animation) { + return ScaleTransition(scale: animation, child: child); + }, + child: IconButton( + key: ValueKey(AppSettings.isDarkMode), + icon: Icon( + AppSettings.isDarkMode ? Icons.dark_mode : Icons.light_mode, + color: AppSettings.isDarkMode + ? TaskWarriorColors.white + : TaskWarriorColors.black, + ), + onPressed: () async { + AppSettings.isDarkMode = !AppSettings.isDarkMode; + await SelectedTheme.saveMode(AppSettings.isDarkMode); + homeController.initLanguageAndDarkMode(); + }, + ), ), - Visibility( - visible: homeController.taskchampion.value, - child: NavDrawerMenuItem( + ), + ], + ), + ); + } + + Widget _buildMenuItems(BuildContext context) { + return ListView( + padding: EdgeInsets.zero, + children: [ + SizedBox(height: Get.height * 0.03), + Visibility( + visible: homeController.taskchampion.value, + child: Column( + children: [ + NavDrawerMenuItem( icon: Icons.task_alt, text: SentenceManager( currentLanguage: homeController.selectedLanguage.value, ).sentences.ccsyncCredentials, onTap: () { + Navigator.of(context).pop(); // Close the drawer Navigator.of(context).push( MaterialPageRoute( builder: (context) => ManageTaskChampionCreds(), @@ -101,130 +112,109 @@ class NavDrawer extends StatelessWidget { ); }, ), - ), - Visibility( - visible: homeController.taskchampion.value, - child: NavDrawerMenuItem( - icon: Icons.delete, - text: SentenceManager( - currentLanguage: homeController.selectedLanguage.value, - ).sentences.deleteTaskTitle, - onTap: () { - showDialog( - context: context, - builder: (BuildContext context) { - return Utils.showAlertDialog( - title: Text( - SentenceManager( - currentLanguage: - homeController.selectedLanguage.value, - ).sentences.deleteTaskConfirmation, - style: TextStyle( - color: AppSettings.isDarkMode - ? TaskWarriorColors.white - : TaskWarriorColors.black, - ), - ), - content: Text( - SentenceManager( - currentLanguage: - homeController.selectedLanguage.value, - ).sentences.deleteTaskWarning, - style: TextStyle( - color: AppSettings.isDarkMode - ? TaskWarriorColors.white - : TaskWarriorColors.black, - ), - ), - actions: [ - TextButton( - child: Text( - 'Cancel', - style: TextStyle( - color: AppSettings.isDarkMode - ? TaskWarriorColors.white - : TaskWarriorColors.black, - ), - ), - onPressed: () { - Navigator.of(context).pop(); // Close the dialog - }, - ), - TextButton( - child: Text( - 'Confirm', - style: TextStyle( - color: AppSettings.isDarkMode - ? TaskWarriorColors.white - : TaskWarriorColors.black, - ), - ), - onPressed: () { - homeController.deleteAllTasksInDB(); - Navigator.of(context).pop(); // Close the dialog - }, - ), - ], - ); - }, - ); - }), - ), - Visibility( - visible: !homeController.taskchampion.value, - child: Obx( - () => NavDrawerMenuItem( + Divider(color: Colors.grey.shade700), + ], + ), + ), + Visibility( + visible: homeController.taskchampion.value, + child: Column( + children: [ + NavDrawerMenuItem( + icon: Icons.delete, + text: SentenceManager( + currentLanguage: homeController.selectedLanguage.value, + ).sentences.deleteTaskTitle, + onTap: () { + Navigator.of(context).pop(); // Close the drawer + _showDeleteConfirmationDialog(context); + }, + ), + Divider(color: Colors.grey.shade700), + ], + ), + ), + Visibility( + visible: !homeController.taskchampion.value, + child: Obx( + () => Column( + children: [ + NavDrawerMenuItem( icon: Icons.person_rounded, text: SentenceManager( currentLanguage: homeController.selectedLanguage.value, ).sentences.navDrawerProfile, onTap: () { + Navigator.of(context).pop(); // Close the drawer Get.toNamed(Routes.PROFILE); }, ), - ), + Divider(color: Colors.grey.shade700), + ], ), - Visibility( - visible: !homeController.taskchampion.value, - child: Obx( - () => NavDrawerMenuItem( + ), + ), + Visibility( + visible: !homeController.taskchampion.value, + child: Obx( + () => Column( + children: [ + NavDrawerMenuItem( icon: Icons.summarize, text: SentenceManager( currentLanguage: homeController.selectedLanguage.value, ).sentences.navDrawerReports, onTap: () { + Navigator.of(context).pop(); // Close the drawer Get.toNamed(Routes.REPORTS); }, ), - ), + Divider(color: Colors.grey.shade700), + ], ), - Visibility( - visible: homeController.taskchampion.value, - child: Obx( - () => NavDrawerMenuItem( + ), + ), + Visibility( + visible: homeController.taskchampion.value, + child: Obx( + () => Column( + children: [ + NavDrawerMenuItem( icon: Icons.summarize, text: SentenceManager( currentLanguage: homeController.selectedLanguage.value, ).sentences.navDrawerReports, onTap: () { + Navigator.of(context).pop(); // Close the drawer Get.to(() => ReportsHomeTaskc()); }, ), - ), + Divider(color: Colors.grey.shade700), + ], ), - Obx( - () => NavDrawerMenuItem( + ), + ), + Obx( + () => Column( + children: [ + NavDrawerMenuItem( icon: Icons.info, text: SentenceManager( currentLanguage: homeController.selectedLanguage.value, ).sentences.navDrawerAbout, onTap: () { + Navigator.of(context).pop(); // Close the drawer Get.toNamed(Routes.ABOUT); }, ), - ), - Obx( - () => NavDrawerMenuItem( + Divider(color: Colors.grey.shade700), + ], + ), + ), + Obx( + () => Column( + children: [ + NavDrawerMenuItem( icon: Icons.settings, text: SentenceManager( currentLanguage: homeController.selectedLanguage.value, @@ -241,24 +231,96 @@ class NavDrawer extends StatelessWidget { homeController.change24hr.value = prefs.getBool('24hourformate') ?? false; + Navigator.of(context).pop(); // Close the drawer Get.toNamed(Routes.SETTINGS); }, ), + Divider(color: Colors.grey.shade700), + ], + ), + ), + ], + ); + } + + Widget _buildExitButton(BuildContext context) { + return Obx( + () => Column( + children: [ + Divider(color: Colors.grey.shade700), + NavDrawerMenuItem( + icon: Icons.exit_to_app, + text: SentenceManager( + currentLanguage: homeController.selectedLanguage.value, + ).sentences.navDrawerExit, + onTap: () { + Navigator.of(context).pop(); // Close the drawer + _showExitConfirmationDialog(context); + }, + ), + ], + ), + ); + } + + Future _showDeleteConfirmationDialog(BuildContext context) async { + return showDialog( + context: context, + builder: (BuildContext context) { + return Utils.showAlertDialog( + title: Text( + SentenceManager( + currentLanguage: homeController.selectedLanguage.value) + .sentences + .deleteTaskConfirmation, + style: TextStyle( + color: AppSettings.isDarkMode + ? TaskWarriorColors.white + : TaskWarriorColors.black, ), - Obx( - () => NavDrawerMenuItem( - icon: Icons.exit_to_app, - text: SentenceManager( - currentLanguage: homeController.selectedLanguage.value, - ).sentences.navDrawerExit, - onTap: () { - _showExitConfirmationDialog(context); - }, + ), + content: Text( + SentenceManager( + currentLanguage: homeController.selectedLanguage.value) + .sentences + .deleteTaskWarning, + style: TextStyle( + color: AppSettings.isDarkMode + ? TaskWarriorColors.white + : TaskWarriorColors.black, + ), + ), + actions: [ + TextButton( + child: Text( + 'Cancel', + style: TextStyle( + color: AppSettings.isDarkMode + ? TaskWarriorColors.white + : TaskWarriorColors.black, + ), + ), + onPressed: () { + Navigator.of(context).pop(); // Close the dialog + }, + ), + TextButton( + child: Text( + 'Confirm', + style: TextStyle( + color: AppSettings.isDarkMode + ? TaskWarriorColors.white + : TaskWarriorColors.black, + ), ), + onPressed: () { + homeController.deleteAllTasksInDB(); + Navigator.of(context).pop(); // Close the dialog + }, ), ], - ), - ), + ); + }, ); }