[vector_graphics] Provide textDirection for semantics label to avoid crash without Directionality (#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/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.
This repo is a companion repo to the main flutter repo. It contains the source code for Flutter's first-party packages (i.e., packages developed by the core Flutter team). Check the packages directory to see all packages.
These packages are also available on pub.
Please file any issues, bugs, or feature requests in the main flutter repo. Issues pertaining to this repository are labeled “package”.
If you wish to contribute a new package to the Flutter ecosystem, please see the documentation for developing packages. You can store your package source code in any GitHub repository (the present repo is only intended for packages developed by the core Flutter team). Once your package is ready you can publish to the pub repository.
If you wish to contribute a change to any of the existing packages in this repo, please review our contribution guide, and send a pull request.
These are the packages hosted in this repository: