widgetWithText method Null safety

Finder widgetWithText(
  1. Type widgetType,
  2. String text,
  3. {bool skipOffstage = true}
)

Looks for widgets that contain a Text descendant with text in it.

Sample code

// Suppose you have a button with text 'Update' in it:
Button(
  child: Text('Update')
)

// You can find and tap on it like this:
tester.tap(find.widgetWithText(Button, 'Update'));

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

Implementation

Finder widgetWithText(Type widgetType, String text, { bool skipOffstage = true }) {
  return find.ancestor(
    of: find.text(text, skipOffstage: skipOffstage),
    matching: find.byType(widgetType, skipOffstage: skipOffstage),
  );
}