如何调试flutter单元测试?

Jus*_*808 5 flutter

我正在尝试点击FlatButton屏幕上有很多,但它们都有独特的Keys。我有一个print作为函数中唯一的一行onPressed。

这是有效的,我在控制台中看到打印行:

expect(find.byKey(Key('q1a2')), findsOneWidget);
await tester.tap(find.byKey(Key('q1a2')));
await tester.pumpAndSettle(Duration(milliseconds: 500));
Run Code Online (Sandbox Code Playgroud)

这不起作用,我在控制台中看不到打印行:

expect(find.byKey(Key('q3a2')), findsOneWidget);
await tester.tap(find.byKey(Key('q3a2')));
await tester.pumpAndSettle(Duration(milliseconds: 500));
Run Code Online (Sandbox Code Playgroud)

两个示例中的传递expect。我该如何调试这个?

小FlatButton部件代码:

FlatButton(
  key: Key('q${questionId}a$score'),
  color: isSelected ? Colors.amberAccent : Colors.transparent,
  highlightColor: Colors.transparent,
  splashColor: Colors.amberAccent.withOpacity(0.2),
  shape: CircleBorder(
    side: BorderSide(
      color: isSelected ? Colors.amberAccent : Colors.grey[300],
      width: 1.0
    )
  ),
  onPressed: () {
    print('WTF!');
  },
  child: Text(
    score.toString(),
    style: TextStyle(
      color: isSelected ? Colors.grey[900] : Colors.grey[600],
      fontSize: isSelected ? 20.0 : 18.0,
      fontWeight: isSelected ? FontWeight.normal : FontWeight.w300
    )
  )
),
Run Code Online (Sandbox Code Playgroud)