Flutter - how to get Text widget on widget test
Please check this simple example.
testWidgets('Test name', (WidgetTester tester) async {// findig the widgetvar textFind = find.text("text_of_field");// checking widget present or notexpect(textFind, findsOneWidget);//getting Text objectText text = tester.firstWidget(textFind);// validating properiesexpect(text.style.color, Colors.black);......}
You can use find.text
https://flutter.io/docs/cookbook/testing/widget/finders#1-find-a-text-widget
testWidgets('finds a Text Widget', (WidgetTester tester) async { // Build an App with a Text Widget that displays the letter 'H' await tester.pumpWidget(MaterialApp( home: Scaffold( body: Text('H'), ), )); // Find a Widget that displays the letter 'H' expect(find.text('H'), findsOneWidget);});