Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Test: Look for a widget inside of another widget

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

like image 528
Diana Avatar asked Sep 11 '25 15:09

Diana


1 Answers

One can use Finder#descendant, exemplified in its doc

    expect(find.descendant(
            of: find.widgetWithText(Row, 'label_1'),
            matching: find.text('value_1')), findsOneWidget);
like image 154
Björn Eiderbäck Avatar answered Sep 14 '25 05:09

Björn Eiderbäck