![](/img/trans.png)
[英]Flutter: How to know if my widget is inside another widget of a specific type?
[英]Flutter Test: Look for a widget inside of another widget
我正在寻找方法来查看我在测试中找到的小部件内部是否有某些文本。 就我而言,我想查找的特定文本不在完整的RadioButtonGroup
内,而是在找到的ElevatedButton
--> firstButton
。 可能吗?
testWidgets('Horizontal Radio Group builds a Row', (tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: simpleRadio
));
expect(find.byType(Row), findsOneWidget);
expect(find.byType(Column), findsNothing);
var optionButtons = find.byType(ElevatedButton);
expect(optionButtons, findsNWidgets(2));
ElevatedButton firstButton = tester.firstWidget(optionButtons);
});
寻找类似的东西: expect(firstButton.findByText('bla'), findsOneWidget);
我认为您正在寻找的是widgetWithText 。 这将找到一个widgetType
小部件,该小部件具有带有给定文本的Text
后代。
因此,对于您的示例,例如:
expect(find.widgetWithText(ElevatedButton, 'bla'), findsOneWidget);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.