diff --git a/packages/flutter/lib/src/widgets/text.dart b/packages/flutter/lib/src/widgets/text.dart index fe4c37f69d96b..031a9820bf920 100644 --- a/packages/flutter/lib/src/widgets/text.dart +++ b/packages/flutter/lib/src/widgets/text.dart @@ -735,6 +735,7 @@ class Text extends StatelessWidget { text: TextSpan( style: effectiveTextStyle, text: data, + locale: locale, children: textSpan != null ? [textSpan!] : null, ), ), @@ -762,6 +763,7 @@ class Text extends StatelessWidget { text: TextSpan( style: effectiveTextStyle, text: data, + locale: locale, children: textSpan != null ? [textSpan!] : null, ), ); diff --git a/packages/flutter/test/widgets/text_semantics_test.dart b/packages/flutter/test/widgets/text_semantics_test.dart index 3232d69fd5c00..967c994002f38 100644 --- a/packages/flutter/test/widgets/text_semantics_test.dart +++ b/packages/flutter/test/widgets/text_semantics_test.dart @@ -173,4 +173,54 @@ void main() { expect(labelToNodeId['has been created.'], ''); expect(labelToNodeId.length, 3); }); + + testWidgets('GIVEN a Text widget with a locale ' + 'WHEN semantics are built ' + 'THEN the SemanticsNode contains the correct language tag', (WidgetTester tester) async { + const Locale locale = Locale('de', 'DE'); + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Text('Flutter 2050', locale: locale), + ), + ); + + final SemanticsNode node = tester.getSemantics(find.byType(Directionality)); + final LocaleStringAttribute localeStringAttribute = + node.attributedLabel.attributes[0] as LocaleStringAttribute; + + expect(node.label, 'Flutter 2050'); + expect(localeStringAttribute.locale.toLanguageTag(), 'de-DE'); + }); + + testWidgets('GIVEN a Text with a locale is within a SelectionContainer ' + 'WHEN semantics are built ' + 'THEN the SemanticsNode contains the correct language tag', (WidgetTester tester) async { + const Locale locale = Locale('de', 'DE'); + const String text = 'Flutter 2050'; + await tester.pumpWidget( + const MaterialApp( + home: SelectionArea(child: Text(text, locale: locale)), + ), + ); + await tester.pumpAndSettle(); + + final SemanticsNode root = tester.binding.pipelineOwner.semanticsOwner!.rootSemanticsNode!; + final List queue = [root]; + SemanticsNode? targetNode; + while (queue.isNotEmpty) { + final SemanticsNode node = queue.removeAt(0); + if (node.label == text) { + targetNode = node; + break; + } + queue.addAll(node.debugListChildrenInOrder(DebugSemanticsDumpOrder.traversalOrder)); + } + final LocaleStringAttribute localeStringAttribute = + targetNode!.attributedLabel.attributes[0] as LocaleStringAttribute; + + expect(targetNode.label, text); + expect(localeStringAttribute.locale.toLanguageTag(), 'de-DE'); + }); } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy