Repository navigation
Commit caddb39
authored
[vector_graphics] Provide textDirection for semantics label to avoid crash without Directionality (flutter#11962)
## 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#175532
## Pre-Review Checklist
- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] page, which explains my
responsibilities.
- [x] I read and followed the [relevant style guides] and ran [the
auto-formatter].
- [x] I signed the [CLA].
- [x] The title of the PR starts with the name of the package surrounded
by square brackets, e.g. `[shared_preferences]`
- [x] I [linked to at least one issue that this PR fixes] in the
description above.
- [x] I followed [the version and CHANGELOG instructions].
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
test-exempt.
- [x] All existing and new tests are passing.1 parent a404e4c commit caddb39
4 files changed
Lines changed: 21 additions & 2 deletions
File tree
- packages/vector_graphics
- lib/src
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
| 541 | + | |
541 | 542 | | |
542 | 543 | | |
543 | 544 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
418 | 435 | | |
419 | 436 | | |
420 | 437 | | |
| |||
0 commit comments