FlutterDriver - how to close showDialog [duplicate]

亡梦爱人 提交于 2020-05-15 10:23:06

问题


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:

  • Tapping the same value as shown above
  • Adding a key in Scaffold, finding the key and tapping
  • Adding keys in other UI elements in the hierarchy, finding and tapping

The error message I receive is:

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


回答1:


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

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

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



回答2:


Add

Navigator.of(context).pop(false);

after

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



来源:https://stackoverflow.com/questions/58716699/flutterdriver-how-to-close-showdialog

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