widgetWithIcon method

Finder widgetWithIcon (Type widgetType, IconData icon, { bool skipOffstage: true })

Looks for widgets that contain an Icon descendant displaying IconData icon in it.

Sample code

// Suppose you have a button with icon 'arrow_forward' in it:
new Button(
  child: new Icon(Icons.arrow_forward)
)

// You can find and tap on it like this:
tester.tap(find.widgetWithIcon(Button, Icons.arrow_forward));

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

Implementation

Finder widgetWithIcon(Type widgetType, IconData icon, { bool skipOffstage = true }) {
  return find.ancestor(
    of: find.byIcon(icon),
    matching: find.byType(widgetType),
  );
}