2

I am looking for the way to see that the widget I have found in the test, has certain text inside. In my case I want to look for the specific text not inside the complete RadioButtonGroup but inside of the found ElevatedButton --> firstButton. Is it possible?

 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);
    
  });

Looking for something like: expect(firstButton.findByText('bla'), findsOneWidget);

Diana
  • 935
  • 10
  • 31

2 Answers2

2

I think what you're looking for is widgetWithText. This'll find a widget of widgetType that has a Text descendant with the given text.

So for your example, something like:

expect(find.widgetWithText(ElevatedButton, 'bla'), findsOneWidget);
pdblasi
  • 126
  • 2
2

One can use Finder#descendant, exemplified in its doc

    expect(find.descendant(
            of: find.widgetWithText(Row, 'label_1'),
            matching: find.text('value_1')), findsOneWidget);