Skip to content

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

Open
mbcorona wants to merge 1 commit into
flutter:mainfrom
mbcorona:vector-graphics-semantics-textdirection
Open

[vector_graphics] Provide textDirection for semantics label to avoid crash without Directionality#11962
mbcorona wants to merge 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

Fixes flutter/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-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 23, 2026
@google-cla

google-cla Bot commented Jun 23, 2026

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-actions github-actions Bot added p: vector_graphics triage-engine Should be looked at in engine triage labels Jun 23, 2026

@gemini-code-assist gemini-code-assist Bot 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 thread packages/vector_graphics/lib/src/vector_graphics.dart
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 23, 2026
@mbcorona mbcorona force-pushed the vector-graphics-semantics-textdirection branch from 24552c1 to 3f59a98 Compare June 25, 2026 15:19
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 25, 2026
@mbcorona mbcorona force-pushed the vector-graphics-semantics-textdirection branch from 3f59a98 to 553b005 Compare June 25, 2026 15:22
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 25, 2026
@mbcorona mbcorona force-pushed the vector-graphics-semantics-textdirection branch from 553b005 to 77d9eb3 Compare June 25, 2026 15:26
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD p: vector_graphics triage-engine Should 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.

1 participant