androidVisibleLabels function
Distinct non-empty labels (text, else content-desc) of nodes with on-screen bounds, in document order. Used to tell the caller what was on screen when nothing matched.
Implementation
List<String> androidVisibleLabels(List<AndroidUiNode> nodes) {
final seen = <String>{};
final labels = <String>[];
for (final node in nodes) {
final bounds = node.bounds;
if (bounds == null || bounds.isEmpty) continue;
for (final label in [node.text, node.contentDesc]) {
final oneLine = oneLineLabel(label);
if (oneLine.isNotEmpty && seen.add(oneLine)) labels.add(oneLine);
}
}
return labels;
}