FlutterDriver-如何关闭showDialog [英] FlutterDriver - how to close showDialog

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

问题描述

我正在使用FlutterDriver,我定义了一个IconButton和一个键集,如下所示:

I am working with FlutterDriver, I have an IconButton defined and a key set as shown:

Center(
  child: IconButton(
    key: Key('moredots'),
    icon: Icon(Icons.more_vert),
    onPressed: () {
      showDialog(
        context: context,
        builder: (_) => tableConfig,        
      );
    },
  ),
)

使用以下代码成功显示该对话框:

The dialog is successfully shown with the following code:

await driver.tap(find.byValueKey('moredots'));

我不知道怎么关闭对话框.我尝试过:

What I can't figure out is how to dismiss the dialog. I've tried:

  • 使用与上面显示的相同的值
  • 在脚手架中添加钥匙,找到钥匙并点击
  • 在层次结构中的其他UI元素中添加键,查找并点击

我收到的错误消息是:

FlutterDriver:点击消息需要很长时间才能完成...

FlutterDriver: tap message is taking a long time to complete...

推荐答案

我发现showDialog()提供了一个ModalBarrier来在显示对话框时停止用户输入.

I figured out that showDialog() presents a ModalBarrier to stop user input while the dialog is shown.

关闭showDialog的诀窍是按类型查找传递给ModalBarrier的代码,如下所示:

The trick to close the showDialog is to find by type passing in the ModalBarrier as shown here:

await driver.tap(find.byType('ModalBarrier'));

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

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