[vector_graphics] Provide textDirection for semantics label to avoid crash without Directionality#11962
Conversation
|
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. |
There was a problem hiding this comment.
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).
24552c1 to
3f59a98
Compare
3f59a98 to
553b005
Compare
…crash without Directionality
553b005 to
77d9eb3
Compare
Description
When a
VectorGraphic(and thereforeSvgPicture, which delegates to it) is given asemanticsLabelbut there is noDirectionalityancestor in the widget tree, the app crashes at frame flush with:The
Semanticsnode created for the label in_VectorGraphicWidgetState.buildpassed a non-emptylabelbut never supplied atextDirection, and did not resolve the ambientDirectionality. With noDirectionalityin scope, the null text direction propagated toSemanticsData, which asserts. (This is why the issue only reproduces outside of aMaterialApp/WidgetsApp, where aDirectionalityis 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 noDirectionalityis in scope.The pre-existing test
Can add semantic labelhad to wrap the widget in aDirectionalityto 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
[shared_preferences]///).