-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Add onSubmitted and onChanged for SearchAnchor and SearchAnchor.bar
#136840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add onSubmitted and onChanged for SearchAnchor and SearchAnchor.bar
#136840
Conversation
HansMuller
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
3b9cd06 to
d3bc723
Compare
5b7b671 to
28cd8be
Compare
12bb600 to
e3da351
Compare
78efeac to
1f2bf2d
Compare
1f2bf2d to
51a5595
Compare
…rchAnchor.bar` (flutter/flutter#136840)
…rchAnchor.bar` (flutter/flutter#136840)
…rchAnchor.bar` (flutter/flutter#136840)
…rchAnchor.bar` (flutter/flutter#136840)
…rchAnchor.bar` (flutter/flutter#136840)
|
I just ran into this issue, and this fix is exactly what I need! Do you know when this will be released? |
…rchAnchor.bar` (flutter/flutter#136840)
…rchAnchor.bar` (flutter/flutter#136840)
…rchAnchor.bar` (flutter/flutter#136840)
…rchAnchor.bar` (flutter/flutter#136840)
…rchAnchor.bar` (flutter/flutter#136840)
…rchAnchor.bar` (flutter/flutter#136840)
…rchAnchor.bar` (flutter/flutter#136840)
…rchAnchor.bar` (flutter/flutter#136840)
…rchAnchor.bar` (flutter/flutter#136840)
need to iron out some issues with it being in focus or not. Also had to update the searchanchor class with some future changes, see: flutter/flutter#136840
…rchAnchor.bar` (flutter/flutter#136840)
After many attempts I couldn't get the searchanchor to correctly listen. I found this bug on GitHub: flutter/flutter#132915 and it has supposably been fixed recently: flutter/flutter#136840. This feature has been merged but is not yet in my version of flutter, so I have chosen to simply my app slightly and just remove the search anchor
|
I came here through #132915 and #137210 because the example given in https://api.flutter.dev/flutter/material/SearchBar-class.html is not mentioning I think the documentation in SearchBar and in SearchAnchor should make clear that
|
|
Is there a way to close the suggestion view after entering text and clicking submit (Not the suggested text)?. Since |
|
I have a working solution that I paste below But to be honest, I don't really like the way
I think it would be much clearer if one had access to the search view itself and its class SearchPage extends StatefulWidget {
const SearchPage({super.key});
@override
State<SearchPage> createState() => _SearchPageState();
}
class _SearchPageState extends State<SearchPage> {
final _searchController = SearchController(); // <-- create a dedicated search controller
void _onTyped(String text) {
// open search view when typing in search bar
if (!_searchController.isOpen) {
_searchController.openView();
}
// get typeahead recommendations
}
void _onSubmitted(String text) {
// close search view after pressing enter or selecting a recommendation.
// (in search bar as well as in search view)
if (_searchController.isOpen) {
_searchController.closeView(text);
}
// execute search
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Padding(
padding: const EdgeInsets.all(4.0),
child: SearchAnchor(
searchController: _searchController, // <-- use dedicated search controller
viewOnChanged: _onTyped, // <- user is typing in search view
viewOnSubmitted: _onSubmitted, // user pressed enter in search view
builder: (context, controller) {
return SearchBar(
controller: controller, // <-- this is the same controller but passed by the builder
onTap: controller.openView,
onChanged: _onTyped, // <-- user is typing in search bar (not search view)
onSubmitted: _onSubmitted, // <-- user pressed enter in search bar (not search view)
padding: const MaterialStatePropertyAll<EdgeInsets>(
EdgeInsets.symmetric(horizontal: 16.0)),
leading: const Icon(Icons.search),
);
},
suggestionsBuilder: (context, controller) {
return [
ListTile(
title: const Text("Item1"),
onTap: () => _onSubmitted("item1"), // <-- user selected a suggestion
)
];
},
),
), |
Fixes #130687 and #132915
This PR is to add two properties:
viewOnChangedandviewOnSubmittedtoSearchAnchorandSearchAnchor.barso we can control the search bar on the search view.Pre-launch Checklist
///).