Skip to content

[vector_graphics] Provide textDirection for semantics label to avoid crash without Directionality - #11962

Merged
mbcorona merged 1 commit into
flutter:mainfrom
mbcorona:vector-graphics-semantics-textdirection
Jul 31, 2026
Merged

[vector_graphics] Provide textDirection for semantics label to avoid crash without Directionality#11962
mbcorona merged 1 commit into
flutter:mainfrom
mbcorona:vector-graphics-semantics-textdirection

Conversation

@mbcorona

Copy link
Copy Markdown
Member

Description

When a VectorGraphic (and therefore SvgPicture, which delegates to it) is given a semanticsLabel but there is no Directionality ancestor in the widget tree, the app crashes at frame flush with:

A SemanticsData object with label "..." had a null textDirection.
package:flutter/src/semantics/semantics.dart: Failed assertion: 'attributedLabel.string == '' || textDirection != null'

The Semantics node created for the label in _VectorGraphicWidgetState.build passed a non-empty label but never supplied a textDirection, and did not resolve the ambient Directionality. With no Directionality in scope, the null text direction propagated to SemanticsData, which asserts. (This is why the issue only reproduces outside of a MaterialApp/WidgetsApp, where a Directionality is normally present — a triager was previously unable to reproduce it for that reason.)

This PR resolves the text direction with Directionality.maybeOf(context) ?? TextDirection.ltr, so a labeled decorative graphic no longer crashes when no Directionality is in scope.

The pre-existing test Can add semantic label had to wrap the widget in a Directionality to pass; this PR adds a regression test that omits the wrapper and verifies no exception is thrown and the label is present.

Issues fixed by this PR

Fixesflutter/flutter#175532

Pre-Review Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran [the auto-formatter].
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I [linked to at least one issue that this PR fixes] in the description above.
  • I followed [the version and CHANGELOG instructions].
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboardflutter-dashboardBot added the CICD Run CI/CD label Jun 23, 2026
@google-cla

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actionsgithub-actionsBot added p: vector_graphics triage-engine Should be looked at in engine triage labels Jun 23, 2026

@gemini-code-assistgemini-code-assistBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request bumps the vector_graphics package version to 1.2.3 and fixes a crash that occurs when a semanticsLabel is provided without an ambient Directionality by fallback-initializing textDirection to TextDirection.ltr. A corresponding widget test has been added to verify this behavior. The review feedback suggests reusing the existing textDirection state variable in the build method instead of performing another lookup with Directionality.maybeOf(context).

Comment threadpackages/vector_graphics/lib/src/vector_graphics.dart
@github-actionsgithub-actionsBot removed the CICD Run CI/CD label Jun 23, 2026
@mbcorona
mbcoronaforce-pushed the vector-graphics-semantics-textdirection branch from 24552c1 to 3f59a98CompareJune 25, 2026 15:19
@flutter-dashboardflutter-dashboardBot added the CICD Run CI/CD label Jun 25, 2026
@mbcorona
mbcoronaforce-pushed the vector-graphics-semantics-textdirection branch from 3f59a98 to 553b005CompareJune 25, 2026 15:22
@github-actionsgithub-actionsBot removed the CICD Run CI/CD label Jun 25, 2026
@mbcorona
mbcoronaforce-pushed the vector-graphics-semantics-textdirection branch from 553b005 to 77d9eb3CompareJune 25, 2026 15:26
@flutter-dashboardflutter-dashboardBot added the CICD Run CI/CD label Jun 25, 2026
@stuartmorgan-g
stuartmorgan-g removed their request for review July 7, 2026 17:53
@mbcorona

Copy link
Copy Markdown
MemberAuthor

Hi @jtmcdole, could you take a look at this PR when you have time?

@gaaclarke
gaaclarke requested review from walley892 and removed request for jtmcdoleJuly 27, 2026 18:10
@gaaclarke

Copy link
Copy Markdown
Member

@walley892 can you take a look at this please?

@walley892walley892 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks straightforward to me, thanks!

@mbcorona
mbcorona merged commit caddb39 into flutter:mainJul 31, 2026
88 checks passed
Subhanshu20135 pushed a commit to The-Developer-Diaries/flutter that referenced this pull request Aug 3, 2026
…r#190441)
flutter/packages@5351d8c...ac87e65
2026-07-31 developeryusuf@icloud.com [google_fonts] Remove failed loads
from pendingFonts (flutter/packages#12240)
2026-07-31 34871572+gmackall@users.noreply.github.com
[google_sign_in_android] Keep `default_web_client_id` resource from
being stripped by resource shrinker (flutter/packages#12075)
2026-07-31 brunocorona.alcantar@gmail.com [vector_graphics] Provide
textDirection for semantics label to avoid crash without Directionality
(flutter/packages#11962)
2026-07-31 43054281+camsim99@users.noreply.github.com
[camera_android_camerax] Update `AGENTS.md` to improve video recording
integration tests (flutter/packages#12301)
If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.
To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose
To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622
Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICDRun CI/CDp: vector_graphicstriage-engineShould be looked at in engine triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A SemanticsData object with label "My Label" had a null textDirection.

3 participants

@mbcorona@gaaclarke@walley892