chore: add focus node to vocab list view search bar (#5011)

This commit is contained in:
ggurdin 2025-12-31 11:23:20 -05:00 committed by GitHub
parent fb2ef4b0a1
commit 2bc093f9f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View file

@ -41,6 +41,7 @@ class ConstructAnalyticsViewState extends State<ConstructAnalyticsView> {
List<ConstructUses>? vocab;
bool isSearching = false;
FocusNode searchFocusNode = FocusNode();
ConstructLevelEnum? selectedConstructLevel;
StreamSubscription<AnalyticsStreamUpdate>? _constructUpdateSub;
@ -65,6 +66,7 @@ class ConstructAnalyticsViewState extends State<ConstructAnalyticsView> {
void dispose() {
searchController.dispose();
_constructUpdateSub?.cancel();
searchFocusNode.dispose();
super.dispose();
}
@ -141,6 +143,14 @@ class ConstructAnalyticsViewState extends State<ConstructAnalyticsView> {
selectedConstructLevel = null;
searchController.clear();
});
WidgetsBinding.instance.addPostFrameCallback((_) {
if (isSearching) {
FocusScope.of(context).requestFocus(searchFocusNode);
} else {
searchFocusNode.unfocus();
}
});
}
@override

View file

@ -125,6 +125,7 @@ class VocabAnalyticsListView extends StatelessWidget {
Expanded(
child: TextField(
autofocus: true,
focusNode: controller.searchFocusNode,
controller: controller.searchController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.symmetric(