whereWidgetProp<T> method

  1. @useResult
WidgetSelector<W> whereWidgetProp<T>(
  1. NamedWidgetProp<W, T> prop,
  2. bool match(
    1. T value
    )
)

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

Example usage:

spotSingle<Checkbox>()
  .whereWidgetProp(
    prop: widgetProp('isChecked', (widget) => widget.value),
    match: (value) => value == true,
  ).existsOnce();

Implementation

@useResult
WidgetSelector<W> whereWidgetProp<T>(
  NamedWidgetProp<W, T> prop,
  bool Function(T value) match,
) {
  return self!.addStage(
    PredicateFilter(
      predicate: (Element element) {
        final widget = self!.mapElementToWidget(element);
        final value = prop.get(widget);
        return match(value);
      },
      description: prop.name,
    ),
  );
}