whereElement method

  1. @useResult
WidgetSelector<W> whereElement(
  1. bool predicate(
    1. Element element
    ), {
  2. required String description,
})

Creates a filter for the discovered elements which is applied when the WidgetSelector is snapshotted.

The description is required to make error messages understandable.

Example usage:

spot<Checkbox>()
  .whereElement(
    (el) => (el.widget as Checkbox).value == true,
    description: 'is checked',
  ).existsOnce();

Implementation

@useResult
WidgetSelector<W> whereElement(
  bool Function(Element element) predicate, {
  required String description,
}) {
  return self.addStage(
    PredicateFilter(
      predicate: predicate,
      description: description,
    ),
  );
}