byElementPredicate method

Finder byElementPredicate (ElementPredicate predicate, { String description, bool skipOffstage: true })

Finds widgets using an element predicate.

Sample code

expect(find.byElementPredicate(
  // finds elements of type SingleChildRenderObjectElement, including
  // those that are actually subclasses of that type.
  // (contrast with byElementType, which only returns exact matches)
  (Element element) => element is SingleChildRenderObjectElement,
  description: '$SingleChildRenderObjectElement element',
), findsOneWidget);

If description is provided, then this uses it as the description of the Finder and appears, for example, in the error message when the finder fails to locate the desired widget. Otherwise, the description prints the signature of the predicate function.

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

Implementation

Finder byElementPredicate(ElementPredicate predicate, { String description, bool skipOffstage = true }) {
  return _ElementPredicateFinder(predicate, description: description, skipOffstage: skipOffstage);
}