From 4e482c6d2b9da283132afc7b62b4351f5a3c8a9d Mon Sep 17 00:00:00 2001 From: sogalabhi Date: Fri, 26 Dec 2025 20:56:13 +0530 Subject: [PATCH] feat(home): add search focus management in HomeController and HomePageBody --- .../modules/home/controllers/home_controller.dart | 14 ++++++++++++++ lib/app/modules/home/views/home_page_body.dart | 1 + 2 files changed, 15 insertions(+) diff --git a/lib/app/modules/home/controllers/home_controller.dart b/lib/app/modules/home/controllers/home_controller.dart index a7b6d353..3531745f 100644 --- a/lib/app/modules/home/controllers/home_controller.dart +++ b/lib/app/modules/home/controllers/home_controller.dart @@ -61,6 +61,7 @@ class HomeController extends GetxController { final RxBool sortHeaderVisible = false.obs; final RxBool searchVisible = false.obs; final TextEditingController searchController = TextEditingController(); + final FocusNode searchFocusNode = FocusNode(); final StringTagController stringTagController = StringTagController(); late RxBool serverCertExists; final Rx selectedLanguage = SupportedLanguage.english.obs; @@ -481,6 +482,12 @@ class HomeController extends GetxController { if (!searchVisible.value) { searchedTasks.assignAll(queriedTasks); searchController.text = ''; + searchFocusNode.unfocus(); // Unfocus when hiding + } else { + // Request focus after the frame is built to ensure widget exists in tree + WidgetsBinding.instance.addPostFrameCallback((_) { + searchFocusNode.requestFocus(); + }); } } @@ -827,4 +834,11 @@ class HomeController extends GetxController { // forReplica: taskReplica.value)); // Get.dialog(showDialog); // } + + @override + void onClose() { + searchFocusNode.dispose(); + searchController.dispose(); + super.onClose(); + } } diff --git a/lib/app/modules/home/views/home_page_body.dart b/lib/app/modules/home/views/home_page_body.dart index a409e8ee..de72cb4a 100644 --- a/lib/app/modules/home/views/home_page_body.dart +++ b/lib/app/modules/home/views/home_page_body.dart @@ -37,6 +37,7 @@ class HomePageBody extends StatelessWidget { margin: const EdgeInsets.symmetric( horizontal: 10, vertical: 10), child: SearchBar( + focusNode: controller.searchFocusNode, backgroundColor: WidgetStateProperty.all( (tColors.primaryBackgroundColor!)), surfaceTintColor: WidgetStateProperty.all(