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;