From 69e8b81f2a4c6a6edcecd636ee5f1a10f998c8df Mon Sep 17 00:00:00 2001 From: Om Dhumal Date: Thu, 8 Jan 2026 14:13:53 +0530 Subject: [PATCH 1/2] auto focus works using FocusNode, and onTapOutside --- lib/app/modules/home/controllers/home_controller.dart | 6 ++++++ lib/app/modules/home/views/home_page_body.dart | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/lib/app/modules/home/controllers/home_controller.dart b/lib/app/modules/home/controllers/home_controller.dart index a7b6d353..8bfb51d9 100644 --- a/lib/app/modules/home/controllers/home_controller.dart +++ b/lib/app/modules/home/controllers/home_controller.dart @@ -65,6 +65,7 @@ class HomeController extends GetxController { late RxBool serverCertExists; final Rx selectedLanguage = SupportedLanguage.english.obs; final ScrollController scrollController = ScrollController(); + final FocusNode searchFocusNode = FocusNode(); final RxBool showbtn = false.obs; late TaskDatabase taskdb; var tasks = [].obs; @@ -478,6 +479,11 @@ class HomeController extends GetxController { void toggleSearch() { searchVisible.value = !searchVisible.value; + if (searchVisible.value) { + Future.delayed(const Duration(milliseconds: 300), () { + searchFocusNode.requestFocus(); + }); + } if (!searchVisible.value) { searchedTasks.assignAll(queriedTasks); searchController.text = ''; diff --git a/lib/app/modules/home/views/home_page_body.dart b/lib/app/modules/home/views/home_page_body.dart index a409e8ee..0e139462 100644 --- a/lib/app/modules/home/views/home_page_body.dart +++ b/lib/app/modules/home/views/home_page_body.dart @@ -43,9 +43,13 @@ class HomePageBody extends StatelessWidget { (tColors.primaryBackgroundColor!)), controller: controller.searchController, // shape:, + focusNode: controller.searchFocusNode, onChanged: (value) { controller.search(value); }, + onTapOutside: (event) { + controller.searchFocusNode.unfocus(); + }, shape: WidgetStateProperty.resolveWith( (Set states) { From 711bc90cda62c2ce58d7aa860dfca3fbbd2d75c4 Mon Sep 17 00:00:00 2001 From: Om Dhumal Date: Thu, 8 Jan 2026 18:24:41 +0530 Subject: [PATCH 2/2] onClose() when app closed --- lib/app/modules/home/controllers/home_controller.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/app/modules/home/controllers/home_controller.dart b/lib/app/modules/home/controllers/home_controller.dart index 8bfb51d9..69bf56d3 100644 --- a/lib/app/modules/home/controllers/home_controller.dart +++ b/lib/app/modules/home/controllers/home_controller.dart @@ -833,4 +833,9 @@ class HomeController extends GetxController { // forReplica: taskReplica.value)); // Get.dialog(showDialog); // } + @override + void onClose() { + searchFocusNode.dispose(); + super.onClose(); + } }