Skip to content

Commit

Permalink
SearchBar: implement blur() method (#4919)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndonkoHenri authored Feb 19, 2025
1 parent 134b993 commit f8c7baa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/flet/lib/src/controls/search_anchor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class _SearchAnchorControlState extends State<SearchAnchorControl> {
bool _focused = false;
late final FocusNode _focusNode;
String? _lastFocusValue;
String? _lastBlurValue;

@override
void initState() {
Expand Down Expand Up @@ -109,10 +110,15 @@ class _SearchAnchorControlState extends State<SearchAnchorControl> {
widget.control.attrString("keyboardType"), TextInputType.text)!;

var focusValue = widget.control.attrString("focus");
var blurValue = widget.control.attrString("blur");
if (focusValue != null && focusValue != _lastFocusValue) {
_lastFocusValue = focusValue;
_focusNode.requestFocus();
}
if (blurValue != null && blurValue != _lastBlurValue) {
_lastBlurValue = blurValue;
_focusNode.unfocus();
}

var method = widget.control.attrString("method");

Expand Down
4 changes: 4 additions & 0 deletions sdk/python/packages/flet/src/flet/core/search_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ def focus(self):
self._set_attr_json("focus", str(time.time()))
self.update()

def blur(self):
self._set_attr_json("blur", str(time.time()))
self.update()

def open_view(self):
m = {
"n": "openView",
Expand Down

0 comments on commit f8c7baa

Please sign in to comment.