Skip to content

Update RichText semantics when only TextSpan semantics fields change - #195756

Draft
ChandraChaan wants to merge 3 commits into
flutter:masterfrom
ChandraChaan:text-span-semantics-compare
Draft

ChandraChaan wants to merge 3 commits into
flutter:masterfrom
ChandraChaan:text-span-semantics-compare

Conversation

@ChandraChaan

Copy link
Copy Markdown

When only semanticsLabel, semanticsIdentifier, locale or spellOut of a TextSpan changes, RichText keeps the old semantics, so a screen reader announces the stale label or locale.

There are two causes:

  • TextSpan.compareTo only checks recognizer for metadata changes, so it returns RenderComparison.identical and RenderParagraph.text returns early. It now returns metadata when any of those four fields differ.
  • The metadata branch of RenderParagraph.text didn't clear _cachedAttributedLabels, which is where the label is built from. It now clears it, like the paint and layout branches.

TextSpan.== and hashCode also ignored locale and spellOut; they now include them.

Tests: compareTo and equality unit tests in text_span_test.dart, and a widget test in rich_text_test.dart that changes the label and then the locale. All three fail without this change. Locally, test/painting and test/rendering pass apart from the localized_fonts_test.dart goldens, which show the same few-pixel differences on a clean checkout.

Fixes #195755

Pre-launch Checklist

TextSpan.compareTo ignored semanticsLabel, semanticsIdentifier, locale
and spellOut, so RenderParagraph kept the old semantics when only those
changed. The metadata branch of RenderParagraph.text also kept the
cached attributed labels. TextSpan == and hashCode now include locale
and spellOut.
@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RichText keeps a stale semantics label when only TextSpan.semanticsLabel or locale changes

1 participant