widgetWithIcon method

Finder widgetWithIcon(
  1. Type widgetType,
  2. IconData icon, {
  3. bool skipOffstage = true,
})

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

Sample code

// Suppose there is a button with icon 'arrow_forward' in it:
const Button(
  child: Icon(Icons.arrow_forward)
);

// It can be found and tapped 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),
  );
}