From b9556a91a0b99538736c67dd4817f43a522c27c2 Mon Sep 17 00:00:00 2001 From: Fokke de Boer Date: Thu, 20 Jun 2024 00:45:59 +0200 Subject: [PATCH] Fix keyboard pop up when autofocus is turned on --- auth/lib/ui/home_page.dart | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/auth/lib/ui/home_page.dart b/auth/lib/ui/home_page.dart index 81fd7ed586..a2f97f07a6 100644 --- a/auth/lib/ui/home_page.dart +++ b/auth/lib/ui/home_page.dart @@ -56,7 +56,7 @@ class _HomePageState extends State { final scaffoldKey = GlobalKey(); final TextEditingController _textController = TextEditingController(); - final FocusNode searchInputFocusNode = FocusNode(); + final bool _autoFocusSearch = PreferenceService.instance.shouldAutoFocusOnSearchBar(); bool _showSearchBox = false; String _searchText = ""; List? _allCodes; @@ -87,18 +87,7 @@ class _HomePageState extends State { _iconsChangedEvent = Bus.instance.on().listen((event) { setState(() {}); }); - _showSearchBox = PreferenceService.instance.shouldAutoFocusOnSearchBar(); - if (_showSearchBox) { - WidgetsBinding.instance.addPostFrameCallback( - (_) { - // https://github.com/flutter/flutter/issues/20706#issuecomment-646328652 - FocusScope.of(context).unfocus(); - Timer(const Duration(milliseconds: 1), () { - FocusScope.of(context).requestFocus(searchInputFocusNode); - }); - }, - ); - } + _showSearchBox = _autoFocusSearch; } void _loadCodes() { @@ -240,8 +229,7 @@ class _HomePageState extends State { : TextField( autocorrect: false, enableSuggestions: false, - focusNode: searchInputFocusNode, - autofocus: _searchText.isEmpty, + autofocus: _autoFocusSearch, controller: _textController, onChanged: (val) { _searchText = val;