escapeSemanticIdSegment function
Escapes a folded key value so it cannot inject the / segment separator or
the ~ positional marker into a derived id (see semanticAnchorOf).
Without this, an app Key whose string form contains ~ (e.g.
ValueKey('a~b'), a path/range) would make a stable id look positional to
the stale-reference guard, and a / would inject phantom segments that break
uniqueness. Percent-style so the escape introduces no / or ~ of its own;
~ in a derived id then unambiguously means "positional segment", never key
content. Contributors that mint child ids from a key (e.g. DataTable rows)
must apply this too.
Implementation
String escapeSemanticIdSegment(String segment) => segment
.replaceAll('%', '%25')
.replaceAll('~', '%7E')
.replaceAll('/', '%2F');