如何使用FlutterDriver关闭对话框 [英] How to close Dialog using FlutterDriver

查看:164
本文介绍了如何使用FlutterDriver关闭对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过"轻按"来关闭对话框,即点击内容之外的内容以使用Flutter Driver将其关闭?

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?

我的问题是该对话框没有任何可关闭它的按钮.而是希望用户在其外部点击或使用后退"按钮.但是, FlutterDriver 没有后退"选项.

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.

推荐答案

在Flutter中,模态常用的键是ModalBarrier,这就是为什么以下方法可以解决问题:

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

只要设置了 barrierDismissible ,此方法就可以工作到true.
本质上,当在Flutter中轻按对话框时,您正在点击模式障碍,这就是上面的代码起作用的原因.

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.

感谢 John Muchow找出了答案.

这篇关于如何使用FlutterDriver关闭对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆