Skip to content

Commit 2c5fbba

Browse files
author
Bruce
committed
[vector_graphics] Provide textDirection for semantics label to avoid crash without Directionality
1 parent 7d84a69 commit 2c5fbba

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

packages/vector_graphics/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## NEXT
22

33
* Updates minimum supported SDK version to Flutter 3.38/Dart 3.10.
4+
* Fixes a crash when a `semanticsLabel` is provided without an ambient `Directionality` (flutter/flutter#175532).
45

56
## 1.2.2
67

packages/vector_graphics/lib/src/vector_graphics.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ class _VectorGraphicWidgetState extends State<VectorGraphic> {
538538
container: widget.semanticsLabel != null,
539539
image: true,
540540
label: widget.semanticsLabel ?? '',
541+
textDirection: Directionality.maybeOf(context) ?? TextDirection.ltr,
541542
child: child,
542543
);
543544
}

packages/vector_graphics/test/vector_graphics_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,23 @@ void main() {
415415
);
416416
});
417417

418+
testWidgets('Semantic label works without an ambient Directionality (flutter/flutter#175532)', (
419+
WidgetTester tester,
420+
) async {
421+
final testBundle = TestAssetBundle();
422+
423+
await tester.pumpWidget(
424+
DefaultAssetBundle(
425+
bundle: testBundle,
426+
child: const VectorGraphic(loader: AssetBytesLoader('foo.svg'), semanticsLabel: 'Foo'),
427+
),
428+
);
429+
await tester.pumpAndSettle();
430+
431+
expect(tester.takeException(), isNull);
432+
expect(find.bySemanticsLabel('Foo'), findsOneWidget);
433+
});
434+
418435
testWidgets('Default placeholder builder', (WidgetTester tester) async {
419436
final testBundle = TestAssetBundle();
420437

0 commit comments

Comments
 (0)