【问题标题】:How to tap all items of a list or a grid in a Flutter widget test?如何在 Flutter 小部件测试中点击列表或网格的所有项目?
【发布时间】:2021-09-15 20:34:45
【问题描述】:

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

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

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

有更优雅的方法吗?

【问题讨论】:

    标签: flutter testing widget-test-flutter


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-12-06
      • 2021-09-22
      • 2020-10-18
      • 2021-01-12
      • 2021-10-30
      • 2020-03-21
      • 1970-01-01
      • 2022-06-24
      • 1970-01-01
      相关资源
      最近更新 更多