Expose onTapOutside from SearchBar's TextField #145096
Copy link
Copy link
Closed
Labels
c: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamOwned by Design Languages team
Description
Use case
All the TextFields in my app are set to lose focus closing the keyboard when they're tapped outside. I can't do the same on SearchBar as the onTapOutside property of TextField class is not exposed.
Proposal
Introduce onTextOutside parameter for SearchBar and SearchAnchor constructors.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
c: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamOwned by Design Languages team
Activity
Sahil-kachhap commentedon Mar 15, 2024
Do you have any other use cases (other than losing the focus) for which you want the
onTapOutsideparameter to be exposed by the Searchbar constructor?If you only want to unfocus it on being tapped outside, this can be implemented internally in the search bar class, and then there would be no need to expose the parameter.
Sahil-kachhap commentedon Mar 15, 2024
WhatsApp.Video.2024-03-15.at.6.59.45.PM.mp4
Here's a fix I have implemented @danagbemava-nc @darshankawar, Let me know if this looks good to go.
And here's what I have done: I utilize the focusNode property of searchbar class and then I use it in onTapOutside property of underlying textfield.
the change has been made here - just added a parameter: onTapOutside
aleripe commentedon Mar 18, 2024
I have no other use case at the moment, but I think it could be more useful to expose it rather than wrap it. But it's your choice!
CicciLeo commentedon Mar 19, 2024
It can be usefull if you want to clear the SearchController value if you tap outside, and keep the text only on submit
Sahil-kachhap commentedon Mar 19, 2024
Thanks @aleripe @CicciLeo for sharing this usecase, I will make the relevant changes in the PR based on your responses.
[Fix]: Searchbar doesn't lose focus when tapped outside (#145232)
github-actions commentedon Apr 9, 2024
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.