8
await widgetTester.tap(find.byType(ElevatedButton));

shows warning : Maybe the widget is actually off-screen, or another widget is obscuring it, or the widget cannot receive pointer events.

Arun Kenjila
  • 129
  • 1
  • 9
  • Sounds reasonable. Did you check if it's the case? – nvoigt Mar 22 '21 at 07:45
  • Sry bro... I didnt get u – Arun Kenjila Mar 22 '21 at 09:20
  • Well, there is a plain text warning. It is supposed to help you. Did you check out if it is actually right and what you can do to solve it? We cannot magically find out whether that button is off-screen in your app. You will have to do that. It's your code on your computer and your device. Did you make sure it is on-screen and not obscured in all screen types? – nvoigt Mar 22 '21 at 09:53
  • Bro.. I hv copied the official widget test mentioned in their website.. It also showing same error.. – Arun Kenjila Mar 22 '21 at 11:50
  • Yes, and have you tried fixing it? Do you *understand* what that error means? We don't know your code. We don't know what you copied (who is "their"?). We don't know what your screen or application looks like. For all we know, this error is *correct*. Post something that convinces us that it's not. – nvoigt Mar 22 '21 at 13:19
  • official means flutter bro – Arun Kenjila Mar 23 '21 at 04:03
  • Nobody here will be able to help you, if you don't post more information. For example a [mcve]. – nvoigt Mar 23 '21 at 06:41
  • tnx bro... for ur time – Arun Kenjila Mar 23 '21 at 07:08

3 Answers3

19

Try this:

await widgetTester.ensureVisible(find.byType(ElevatedButton));
await widgetTester.pumpAndSettle();
await widgetTester.tap(find.byType(ElevatedButton));
Alireza
  • 193
  • 1
  • 5
3

I just replace await tester.pump(); by await tester.pumpAndSettle(); before tap

It works for me.

Nguyễn Anh Tuấn
  • 1,023
  • 1
  • 12
  • 19
0

I suggest creating a safeTapBy function logic. This just ensures that the button is visible (keyboard showing, off screen etc). Here is an example using find.byKey:

Future safeTapByKey(WidgetTester tester, String key) async {
  await tester.ensureVisible(find.byKey(Key(key)));
  await tester.pumpAndSettle();
  await tester.tap(find.byKey(Key(key)));
}
jbryanh
  • 1,193
  • 7
  • 17