[auth] Potential fix for keyboard popup not working while focusing on… (#1428)

… search

## Description

## Tests
This commit is contained in:
Neeraj Gupta 2024-04-13 12:15:49 +05:30 committed by GitHub
commit 555a960def
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -51,6 +51,7 @@ class _HomePageState extends State<HomePage> {
final scaffoldKey = GlobalKey<ScaffoldState>();
final TextEditingController _textController = TextEditingController();
final FocusNode searchInputFocusNode = FocusNode();
bool _showSearchBox = false;
String _searchText = "";
List<Code> _codes = [];
@ -80,6 +81,17 @@ class _HomePageState extends State<HomePage> {
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);
});
},
);
}
}
void _loadCodes() {
@ -192,6 +204,7 @@ class _HomePageState extends State<HomePage> {
title: !_showSearchBox
? const Text('Ente Auth')
: TextField(
focusNode: searchInputFocusNode,
autofocus: _searchText.isEmpty,
controller: _textController,
onChanged: (val) {