How to dismiss flutter autocomplete popup? - flutter

The AutoComplete widget will automatically popup the dropdown list every time you clicked in the textfield. The problem is the popup cannot be dismissed unless you deliberately input some wrong words or select one item in the popup list. This leads to unwanted result.
You can check this behavior in this dartpad or on the official document.
I expect the popup can be dismissed by hitting the esc key or clicking outside the popup, so that I can see the import thing underneath.
Has I missed something or it's simply a bug?

from source code , they are three conditions to show a options view
bool get _shouldShowOptions {
return _focusNode.hasFocus && _selection == null && _options.isNotEmpty;
}
it seems that unfocus the underlying textfield is the simplest solution

Related

Keep keyboard open on page and disable every close option

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());

Flutter Clear Search Text Persists Search

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.

How to close Dialog using FlutterDriver

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

tvOS: How to disable Next and Done button on UIKeyBoard?

After making usernameTextfield firstresponder, I see below screen for entering username.
I want to disble (or not focused) Next button until textfield has 0 characters. How can I do it?
Also, how can I capture tv remotes Back and Press event on keyboard?
I read other post How to disable/enable the return key in a UITextField? but It didn't helped me.
In apple docs, it's mentioned that
optional public var enablesReturnKeyAutomatically: Bool { get set } // default is NO (when YES, will automatically disable return key when text widget has zero-length contents, and will automatically enable when text widget has non-zero-length contents)
If this is not possible, then is it possible to add tapgesturerecognizer on this screen so that I can know when user click or pressed Menu button on Remote?
As of now my research says its not possible to disable return key ( Next / Done ) in tvOS but its possible to know when user clicked Next or Done button on keyboard by using .primaryActionTriggered event.

How to avoid CellList/Table from automatically scrolling to selected item when visible range is changed

I was implementing a custom CellTable that has a infinite scroll feature using the CellList showcase example ( http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellList ). However, I found a feature in CellList/Table that is undesirable in this case: changing visible range after clicking an item would cause the List/Table to be automatically scrolled to the selected item.
you can try the showcase example in above to see the exact same behavior. When no item is selected, the infinite scroll works just fine, but when you click an item and then scroll it, it will always jump back to the selected item when the range is changed.
I also found that it only happens when the focus is still on the item, that is, if you select an item and then click somewhere else to lose the focus, it wouldn't happen.
I've been digging around the GWT code and trying to find out how to disable this feature with no success. Did anyone handled this situation before?
As a simple workaround, you can call focus() on some element, to remove the focus from the item (without removing the selection).
In the showcase example, in ShowMorePagerPanel, add e.g.
scrollable.getElement().focus();
at the beginning of the onScroll(ScrollEvent event) method.
I ran into the same problem and couldn't get Chris's answer to solve it, but the following solution worked for me:
in your onScroll(ScrollEvent event) method, add a line similar to the following, assuming yourTable is an instance of something extending AbstractHasData
yourTable.setFocus(false);