1

在我的 Flutter 小部件测试中,我想点击列表或网格视图中的所有(或前 n 个)项目。

我已经想出了一个解决方案,虽然它似乎有效,但再次按键找到点击目标看起来过于复杂:

for (final element in find.byType(ListTile).evaluate()) {
  await tester.tap(find.byKey(element.widget.key!));
}

有没有更优雅的方法来做到这一点?

4

1 回答 1

0

您可以点击小部件上的某个位置:例如点击小部件的中心

for (final element in find.byType(ListTile).evaluate()) {
  await tester.tapAt(tester.getCenter(find.byWidget(element.widget)));
}

于 2021-09-15T22:06:24.487 回答