Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 528
Seth Ladd Avatar asked Nov 25 '25 22:11

Seth Ladd


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.

like image 155
Yegor Avatar answered Nov 28 '25 00:11

Yegor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!