I have a Text Field with _searchController and a separate IconButton that clears the _searchController:
_placesList are the search results.
I also have a method _onSearchChanged that is a listener for the _searchController:
The _onSearchChanged method calls another method that makes an API call if the search controller is not empty:
When the cancel icon button is pressed, I found (through debugging) that the search controller listener is triggered before the search controller text is cleared and therefore an API call is made and THEN the search controller text is actually cleared.
This leaves a list of unwanted search results on the screen.
Hitting the cancel icon button a 2nd time results in the desired outcome of clearing the search results. But obviously I don't want the user to have to press the cancel icon button twice.
I want the cancel icon button to clear the search text and the search results.
I believe you are missing setState here.
Simply wrap the _searchController.clear(); in it like tihs:
setState( () {_searchController.clear();} );
Otherwise flutter won't rebuild with the new data.
This is a common mistake that people forget about.
Related
I want to stop searching for every words in onchanged() textfield and also tried searchdelete same action happening here . so I want to search in set of words or when stop typing. and call api request
Any other way to search
You can listen to onSubmitted or onEditingComplete
onSubmitted → ValueChanged?
Called when the user indicates that they are done editing the text in the field. [...]
final
The onEditingComplete callback also runs when the user finishes editing. It's different from onSubmitted because it has a default value which updates the text controller and yields the keyboard focus. Applications that require different behavior can override the default onEditingComplete callback.
I am building a page where when user is performing an action all the click action should be voided, except certain button. The page will consist of quite a number of clickable action, so I wrapped them in IgnorePointer, however, there's also a button that I need to allow it no matter what.
Are there widget for this? Or there's no feature for this?
I have an app with 2 pages. The first page is the main menu, and when you navigate to the 2nd page, a keyboard open himself inside a TextField (autofocus).
What I want to do is disabling every ways of closing the keyboard. Right now, it doesn't close when you submit, but that's the only thing I achieved to do.
The user can still close it with every other ways (in my case, it's the android navigation bar who has the left button who can dismiss it).
Is there any ways to keep the keyboard open during the whole time an user stays on a page?
EDIT:
I found this package : keyboard_visibility to do that inside initState:
KeyboardVisibilityNotification().addNewListener(onHide: () {
setState(() {
FocusScope.of(context).requestFocus(_focus);
});
});
Each time I hide the keyboard, onHide is called and I can execute some code. Here I try to focus the TextInput again to re-open the keyboard immediately. When the keyboard is hided, the function is called, but requestFocus doesn't seems to work.
Try this,
FocusScope.of(context).requestFocus(FocusNode());
Is there any way to close a dialog by "tapping it away", i.e. tapping outside of the content to close it with Flutter Driver?
My problem is that the dialog does not have any buttons that would close it. Instead the user is expected to either tap outside of it or use the back button. However, FlutterDriver does not have a "back" option.
Hence, I am wondering how I would tap outside of the dialog in order to close it.
The key that is commonly used for modals in Flutter is ModalBarrier, which is why the following should do the trick:
await driver.tap(find.byType(ModalBarrier));
This will work as long as barrierDismissible is set to true.
Essentially, when tapping away a dialog in Flutter, you are tapping on the modal barrier, which is why above code works.
Thanks to John Muchow for finding out.
You would want to set the barrierDismissible property of the dialog to true and add a barrierLabel.
This will allow you to tap outside and close the dialog
https://api.flutter.dev/flutter/widgets/showGeneralDialog.html
(Duplicate of this question, but I figured I could try again, since that one wasn't answered...)
The UISearchBar on the iPhone has an option showsSearchResultsButton. When you turn it on, it shows a button with horizontal lines inside the search bar, and you can implement a callback that will be called when the user presses it.
The thing is, I can't find a single place on the Internet where it says what the intended purpose of this button is. I know I could make it do anything, but I'd like to know what it's actually for. Should it show a history of searches, or all items without filtering, or what?
It's simply to show search results when tapped.
Where Apple uses this is in their iPad App Store application. If you go to the Categories tab you'll see various app categories. Search for an item, you'll get a list of results, and when you press "Done" you are shown the categories screen again. Your previous search term is still listed in the search field, but now the Search Results Button appears in the field. After tapping this, a UIPopOver is displayed, showing a text list of the results from your last search.