Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 728
creativecreatorormaybenot Avatar asked Jun 14 '19 17:06

creativecreatorormaybenot


1 Answers

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.

like image 63
creativecreatorormaybenot Avatar answered Sep 20 '22 08:09

creativecreatorormaybenot