Can I get the text, or other attributes of a widget, once I find it?

Viewed 1769

I'm writing a unit or integration test for Flutter. Can I get the text, or other attributes of a widget, once I find it?

1 Answers

Yes, WidgetTester provides multiple methods for probing into the UI tree (widgets, states, elements, render objects). Here's an example of how you can use it to read out the text out of a Text widget:

tester.widget(find.byType(Text)).data;

See also https://flutter.io/testing/#widget-testing, which explains how to write widget tests in Flutter.

Related