FlutterDriver - how to close showDialog [duplicate]
Asked Answered
C

2

3

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...

Celaeno answered 5/11, 2019 at 17:38 Comment(0)
C
2

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));
Celaeno answered 6/11, 2019 at 3:42 Comment(1)
Doesn't work for me with Flutter 1.17.5. Which version are you using?Shillelagh
G
0

Add

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

after

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

Geanine answered 5/11, 2019 at 18:3 Comment(3)
what does .pop(false) do?Griseldagriseldis
You don't need the false, but its the return value when dialogue is closed.Geanine
Thanks for the input, however, this answer will not work, integration tests with FlutterDriver cannot have Flutter UI code.Celaeno

© 2022 - 2024 — McMap. All rights reserved.