问题
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.
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/56602717/how-to-close-dialog-using-flutterdriver