Skip to content

Wrong semantics order in nested Text.rich #176570

Description

@JankoLancer

Steps to reproduce

The semantics label is not composed in the proper order when there are nested Text.rich widgets. Here is the test reproducing the issue. NOTE: This worked as expected until the 3.32 version.

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

Expected results

The semantic label should be "before foo after", so test should pass.

Actual results

Expected: has semantics with label: before
          foo
           after 
  Actual: SemanticsNode:<SemanticsNode#1(Rect.fromLTRB(0.0, 0.0, 800.0, 115.0) scaled by 3.0x,
label: "before\nafter\nfoo", textDirection: ltr)>
   Which: label was: before
          after
          foo

Code sample

Code sample
 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'),
          ],
        ),
      ),
    ),
  );

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.29.3, on macOS 15.6.1 24G90 darwin-arm64, locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2025.1)
[✓] VS Code (version 1.104.1)
[✓] Connected device (4 available)
[✓] Network resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our testsc: regressionIt was better in the past than it is nowfound in release: 3.35Found to occur in 3.35found in release: 3.37Found to occur in 3.37frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-accessibilityOwned by Framework Accessibility team (i.e. responsible for accessibility code in flutter/flutter)triaged-accessibilityTriaged by Framework Accessibility team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions