diff --git a/packages/flutter/lib/src/painting/text_span.dart b/packages/flutter/lib/src/painting/text_span.dart index a80ce78bd2..0887794738 100644 --- a/packages/flutter/lib/src/painting/text_span.dart +++ b/packages/flutter/lib/src/painting/text_span.dart @@ -371,13 +371,14 @@ class TextSpan extends InlineSpan implements HitTestTarget, MouseTrackerAnnotati final bool effectiveSpellOut = spellOut ?? inheritedSpellOut; if (text != null) { + final int textLength = semanticsLabel?.length ?? text!.length; collector.add(InlineSpanSemanticsInformation( text!, stringAttributes: [ - if (effectiveSpellOut) - ui.SpellOutStringAttribute(range: TextRange(start: 0, end: semanticsLabel?.length ?? text!.length)), - if (effectiveLocale != null) - ui.LocaleStringAttribute(locale: effectiveLocale, range: TextRange(start: 0, end: semanticsLabel?.length ?? text!.length)), + if (effectiveSpellOut && textLength > 0) + ui.SpellOutStringAttribute(range: TextRange(start: 0, end: textLength)), + if (effectiveLocale != null && textLength > 0) + ui.LocaleStringAttribute(locale: effectiveLocale, range: TextRange(start: 0, end: textLength)), ], semanticsLabel: semanticsLabel, recognizer: recognizer, diff --git a/packages/flutter/test/rendering/paragraph_test.dart b/packages/flutter/test/rendering/paragraph_test.dart index 3f85e37119..b8e2cb08e2 100644 --- a/packages/flutter/test/rendering/paragraph_test.dart +++ b/packages/flutter/test/rendering/paragraph_test.dart @@ -749,6 +749,18 @@ void main() { paragraph.assembleSemanticsNode(SemanticsNode(), SemanticsConfiguration(), []); }); + test('Supports empty text span with spell out', () { + final RenderParagraph paragraph = RenderParagraph( + const TextSpan(text: '', spellOut: true), + textDirection: TextDirection.rtl, + ); + layout(paragraph); + final SemanticsNode node = SemanticsNode(); + paragraph.assembleSemanticsNode(node, SemanticsConfiguration(), []); + expect(node.attributedLabel.string, ''); + expect(node.attributedLabel.attributes.length, 0); + }); + test('Asserts on unsupported gesture recognizer', () { final RenderParagraph paragraph = RenderParagraph( TextSpan(text: _kText, children: [