firstVisibleText method
Implementation
String? firstVisibleText(
List<String> candidates, {
ElementTarget? target,
}) {
Finder? targetFinder;
if (target != null) {
try {
targetFinder = resolveTargetFinder?.call(target);
} on TestExecutionError catch (error) {
if (error.code != TestExecutionErrorCode.elementNotFound) rethrow;
}
if (targetFinder == null || targetFinder.evaluate().isEmpty) return null;
}
for (final text in candidates) {
if (target == null) {
if (assertions.isTextVisible(text)) return text;
continue;
}
final matching = find.text(text, skipOffstage: false).evaluate().where(
(element) {
if (!assertions.isElementVisuallyActionable(element)) return false;
if (targetFinder != null) {
final targetElements = targetFinder.evaluate();
return targetElements.any((targetElement) {
if (identical(element, targetElement)) return true;
var withinTarget = false;
element.visitAncestorElements((ancestor) {
if (identical(ancestor, targetElement)) {
withinTarget = true;
return false;
}
return true;
});
return withinTarget;
});
}
return false;
},
);
if (matching.isNotEmpty) return text;
}
return null;
}