Skip to content

Commit 288a82e

Browse files
authored
auto focus works using FocusNode, and onTapOutside
PR #554 ---------- * auto focus works using FocusNode, and onTapOutside * onClose() when app closed
1 parent dd74e6f commit 288a82e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/app/modules/home/controllers/home_controller.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class HomeController extends GetxController {
6161
late RxBool serverCertExists;
6262
final Rx<SupportedLanguage> selectedLanguage = SupportedLanguage.english.obs;
6363
final ScrollController scrollController = ScrollController();
64+
final FocusNode searchFocusNode = FocusNode();
6465
final RxBool showbtn = false.obs;
6566
late TaskDatabase taskdb;
6667
var tasks = <TaskForC>[].obs;
@@ -480,6 +481,11 @@ class HomeController extends GetxController {
480481

481482
void toggleSearch() {
482483
searchVisible.value = !searchVisible.value;
484+
if (searchVisible.value) {
485+
Future.delayed(const Duration(milliseconds: 300), () {
486+
searchFocusNode.requestFocus();
487+
});
488+
}
483489
if (!searchVisible.value) {
484490
searchedTasks.assignAll(queriedTasks);
485491
searchController.text = '';
@@ -874,4 +880,9 @@ class HomeController extends GetxController {
874880
// forReplica: taskReplica.value));
875881
// Get.dialog(showDialog);
876882
// }
883+
@override
884+
void onClose() {
885+
searchFocusNode.dispose();
886+
super.onClose();
887+
}
877888
}

lib/app/modules/home/views/home_page_body.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ class HomePageBody extends StatelessWidget {
4343
(tColors.primaryBackgroundColor!)),
4444
controller: controller.searchController,
4545
// shape:,
46+
focusNode: controller.searchFocusNode,
4647
onChanged: (value) {
4748
controller.search(value);
4849
},
50+
onTapOutside: (event) {
51+
controller.searchFocusNode.unfocus();
52+
},
4953

5054
shape: WidgetStateProperty.resolveWith<OutlinedBorder?>(
5155
(Set<WidgetState> states) {

0 commit comments

Comments
 (0)