How to close Dialog using FlutterDriver - flutter

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

Related

Whenever i try to comeback from another screen my keyboard pop up everytime in flutter

while cooming back from any screen to homescreen my keyboard pop-ups automatically which makes user experience bad.
Can someone tell me how to deal with this bug.
you can run this code everywhere you change page:
FocusManager.instance.primaryFocus?.unfocus()
github issue
Remove what you set in textfield as autofocus true.

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 prevent GWT dialogbox from closing when clicking outside it

I plan to add a menu that pop ups when a user performs a certain action. This menu will include some fields that the user will fill out and then hit "Submit" which will close the dialog box and update the client based on information inputed.
However, I want the user to be able to close the dialog window by hitting cancel or submit, and not by clicking on the screen outside of the dialog box.
How can i do this? Or maybe I should just use a PopupPanel?
It's as easy as setting the auto-hide behavior to false, either at construction time or later.

GWT-Google web Toolkit-DialogBox

I have doubt regarding GWT .In Gwt if i click one button than it shows one dialog box at th same time the form outside the dialog box disabled.What component can be used for this task?
Thanks in advance
So, you want to open a popup dialog box, and at the same time disable the rest of the page until the user closes the dialog box?
If so, you can simply use gwt's DialogBox.
Use the constructor with the autohide flag set to false, and the box will not close until the user responds, thus disabling the rest of the page. If you want to make this even more clear, use the glass effect:
yourBox.setGlassEnabled(true);
You can also use the PopupPanel directly and build your own custom dialog box.
Now, if I got it wrong and you want to disable the form so it remains disabled after the popup, just disable it in the onClick handler of the button that opens the box.