chore: add focus node to vocab list view search bar (#5011)
This commit is contained in:
parent
fb2ef4b0a1
commit
2bc093f9f5
2 changed files with 11 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue