resolveClickName function
The name a tap is reported under, first match wins:
- the host's ClickTarget.identifier, verbatim — so an existing
<id>_pressednever changes; - the label, slugged;
- the visible text, slugged;
- (RN and Flutter) the icon / image / SVG name, ClickTarget.visual;
- the role, else the component, lowercased.
Steps 2 to 4 are skipped for a ClickTarget.redacted control. An identifier that identifiesSomeone is skipped too.
Implementation
ClickName resolveClickName(ClickTarget target) {
final identifier = target.identifier?.trim();
if (identifier != null &&
identifier.isNotEmpty &&
!identifiesSomeone(identifier)) {
return ClickName(identifier, isFallback: false);
}
if (!target.redacted) {
for (final source in [target.label, target.text]) {
final stem = slugClickName(source);
if (stem.isNotEmpty) return ClickName(stem, isFallback: false);
}
final visual = target.visual?.trim();
if (visual != null && visual.isNotEmpty) {
return ClickName(visual, isFallback: false);
}
}
final component = target.component.toLowerCase();
return ClickName(
target.role ?? (component.isEmpty ? 'view' : component),
isFallback: true,
);
}