idForLabel function
The glintId to use when wanted is visible text rather than an id: the nearest tappable ancestor of the matching text, else the text itself; pages under the active one are skipped.
Implementation
String? idForLabel(SceneNode root, String wanted) {
final want = wanted.trim().toLowerCase();
if (want.isEmpty) return null;
final active = _activePage(root);
String? visit(SceneNode n, String? tappable, bool inPage) {
if (n.isOffstage) return null;
if (!inPage && kPageScaffolds.contains(n.baseLabel)) {
if (!identical(n, active)) return null;
inPage = true;
}
final here = n.glintId != null && _tappable(n.baseLabel) ? n.glintId : tappable;
if ((n.textPreview ?? '').trim().toLowerCase() == want) return here ?? n.glintId;
for (final c in n.children) {
final f = visit(c, here, inPage);
if (f != null) return f;
}
return null;
}
return visit(root, null, false);
}