text method Null safety

Finder text(
  1. String text,
  2. {bool findRichText = false,
  3. bool skipOffstage = true}
)

Finds Text, EditableText, and optionally RichText widgets containing string equal to the text argument.

If findRichText is false, all standalone RichText widgets are ignored and text is matched with Text.data or Text.textSpan. If findRichText is true, RichText widgets (and therefore also Text and Text.rich widgets) are matched by comparing the InlineSpan.toPlainText with the given text.

For EditableText widgets, the text is always compared to the current value of the EditableText.controller.

If the skipOffstage argument is true (the default), then this skips nodes that are Offstage or that are from inactive Routes.

Sample code

expect(find.text('Back'), findsOneWidget);

This will match Text, Text.rich, and EditableText widgets that contain the "Back" string.

expect(find.text('Close', findRichText: true), findsOneWidget);

This will match Text, Text.rich, EditableText, as well as standalone RichText widgets that contain the "Close" string.

Implementation

Finder text(
  String text, {
  bool findRichText = false,
  bool skipOffstage = true,
}) {
  return _TextFinder(
    text,
    findRichText: findRichText,
    skipOffstage: skipOffstage,
  );
}