text property
String?
get
text
If the first widget found by this finder is a Text or RichText widget, then this method returns its data.
If you want to make sure that that widget is visible, first use waitUntilVisible method:
expect(await $(Key('Sign in Button')).waitUntilVisible().text, 'Sign in');
Otherwise it throws a PatrolFinderException.
Implementation
String? get text {
final elements = finder.evaluate();
if (elements.isEmpty) {
throw PatrolFinderException('Finder "${toString()}" found no widgets');
}
final firstWidget = elements.first.widget;
if (firstWidget is Text) {
return firstWidget.data;
}
if (firstWidget is RichText) {
return (firstWidget.text as TextSpan).toPlainText();
}
throw PatrolFinderException(
'The first ${firstWidget.runtimeType} widget resolved by this finder '
'is not a Text or RichText widget',
);
}