Skip to content

Text.rich does not compose its semantics label in the correct order for embedded widgets #111931

@marcianx

Description

@marcianx

b/247794358

Steps to Reproduce

The rich text widget doesn't seem to compose the semantics labels in correct order. It seems to concatenate all the TextSpans, replacing an embedded WidgetSpan with u+fffc (unicode object replacement character), and concatenates the WidgetSpan label at the end. Here's a test reproducing the issue:

testWidgets('semantics label not in order', (tester) async {
  await tester.pumpWidget(
    Directionality(
      textDirection: TextDirection.ltr,
      child: Text.rich(
        TextSpan(
          children: [
            TextSpan(text: 'before '),
            WidgetSpan(
              alignment: PlaceholderAlignment.baseline,
              baseline: TextBaseline.alphabetic,
              child: Semantics(label: 'foo'),
            ),
            TextSpan(text: ' after'),
          ],
        ),
      ),
    ),
  );
  expect(tester.getSemantics(find.byType(Text)),
      matchesSemantics(label: 'before foo after'));
});

Error message:

Expected: has semantics with label: before foo after without actions:
  <content removed>
  Actual: SemanticsNode:<SemanticsNode#1(Rect.fromLTRB(0.0, 0.0, 1591.0, 893.0), label: "before 
after\nfoo", textDirection: ltr)>
   Which: label was: before  after
          foo

Expected: The test should pass. Specifically, the semantic label should be "before foo after".

Actual: It's computing the semantic string as "before  after\nfoo". In between "before " and " after", there is a u+fffc unicode character (object replacement character), which is not meaningful to screen readers.

Metadata

Metadata

Assignees

Labels

P0Critical issues such as a build break or regressiona: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)customer: googleVarious Google teamsframeworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions