【发布时间】:2019-12-06 14:55:20
【问题描述】:
我想为 Stack 进行小部件测试。这是示例代码
final List<Widget> children = [];
final stack = Stack(children: children);
await tester.pumpWidget(Container(child: stack));
...
final stackFinder = find.byWidget(stack);
expect(stackFinder, findsOneWidget);
// children should be in Stack
final childrenFinder = find.descendant(
of: stackFinder,
matching: find.byType(children.runtimeType),
);
expect(childrenFinder, findsWidgets);
但得到错误:
Expected: at least one matching node in the widget tree
Actual: ?:<zero widgets with type "List<Widget>" that has ancestor(s) with type "Stack"
我尝试将匹配更改为matching: find.byType([].runtimeType), 或matching: find.byType(List<Widget>),,但它也不起作用。
你知道怎么解决吗?或者,如果不可能,您使用哪种方法来验证里面的孩子的数量?
【问题讨论】: