all method
Asserts that all widgets in the matched set fulfill the provided matcher
.
Applies matcher
to each widget. If any fail, throws a TestFailure
with details of the mismatches.
Implementation
MultiWidgetMatcher<W> all(void Function(WidgetMatcher<W>) matcher) {
TestAsyncUtils.guardSync();
if (discovered.isEmpty) {
throw Exception('Expected at least one match for $this, but found none');
}
late String matcherDescription;
final missMatches = discovered.whereNot((wm) {
try {
matcher(wm);
return true;
} catch (e) {
matcherDescription =
e is PropertyCheckFailure ? e.matcherDescription : e.toString();
return false;
}
}).toList();
if (missMatches.isEmpty) {
return this;
}
throw TestFailure(
"Expected that all candidates fulfill matcher '$matcherDescription', but only ${discovered.length - missMatches.length} of ${discovered.length} did.\n"
'Mismatches: ${missMatches.map((e) => e.element.toStringDeep()).join(', ')}');
}