Feat: automatically collapse search bar when focus is lost
This commit is contained in:
1 parent
6df0a62b32
commit
4b4ed5e742
1 file changed
+18
-1
@@ -64,7 +64,13 @@ class _AppSearchBarState extends ConsumerState<AppSearchBar> {
|
||||
}
|
||||
|
||||
void _onFocusChanged() {
|
||||
if (mounted) setState(() {});
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
if (!_focusNode.hasFocus && widget.collapsible) {
|
||||
_isExpanded = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (_focusNode.hasFocus && widget.enableHistory) {
|
||||
_showOverlay();
|
||||
@@ -199,6 +205,17 @@ class _AppSearchBarState extends ConsumerState<AppSearchBar> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!_isExpanded && widget.collapsible) {
|
||||
if (_hasText) {
|
||||
return IconButton(
|
||||
onPressed: () {
|
||||
_controller.clear();
|
||||
widget.onChanged?.call('');
|
||||
if (widget.onSubmitted != null) widget.onSubmitted!('');
|
||||
},
|
||||
icon: const Icon(Icons.close, size: 28, color: Colors.redAccent),
|
||||
tooltip: 'Clear search',
|
||||
);
|
||||
}
|
||||
return IconButton(
|
||||
onPressed: () {
|
||||
setState(() => _isExpanded = true);
|
||||
|
||||
Reference in new issue
Block a user