How to close Dialog using FlutterDriver

折月煮酒 提交于 2020-05-08 08:17:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!