Unverified Commit 74ac7c47 authored by chunhtai's avatar chunhtai Committed by GitHub

Fix empty textspan with spell out crashes (#88738)

parent 577832fb
...@@ -371,13 +371,14 @@ class TextSpan extends InlineSpan implements HitTestTarget, MouseTrackerAnnotati ...@@ -371,13 +371,14 @@ class TextSpan extends InlineSpan implements HitTestTarget, MouseTrackerAnnotati
final bool effectiveSpellOut = spellOut ?? inheritedSpellOut; final bool effectiveSpellOut = spellOut ?? inheritedSpellOut;
if (text != null) { if (text != null) {
final int textLength = semanticsLabel?.length ?? text!.length;
collector.add(InlineSpanSemanticsInformation( collector.add(InlineSpanSemanticsInformation(
text!, text!,
stringAttributes: <ui.StringAttribute>[ stringAttributes: <ui.StringAttribute>[
if (effectiveSpellOut) if (effectiveSpellOut && textLength > 0)
ui.SpellOutStringAttribute(range: TextRange(start: 0, end: semanticsLabel?.length ?? text!.length)), ui.SpellOutStringAttribute(range: TextRange(start: 0, end: textLength)),
if (effectiveLocale != null) if (effectiveLocale != null && textLength > 0)
ui.LocaleStringAttribute(locale: effectiveLocale, range: TextRange(start: 0, end: semanticsLabel?.length ?? text!.length)), ui.LocaleStringAttribute(locale: effectiveLocale, range: TextRange(start: 0, end: textLength)),
], ],
semanticsLabel: semanticsLabel, semanticsLabel: semanticsLabel,
recognizer: recognizer, recognizer: recognizer,
......
...@@ -749,6 +749,18 @@ void main() { ...@@ -749,6 +749,18 @@ void main() {
paragraph.assembleSemanticsNode(SemanticsNode(), SemanticsConfiguration(), <SemanticsNode>[]); paragraph.assembleSemanticsNode(SemanticsNode(), SemanticsConfiguration(), <SemanticsNode>[]);
}); });
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(), <SemanticsNode>[]);
expect(node.attributedLabel.string, '');
expect(node.attributedLabel.attributes.length, 0);
});
test('Asserts on unsupported gesture recognizer', () { test('Asserts on unsupported gesture recognizer', () {
final RenderParagraph paragraph = RenderParagraph( final RenderParagraph paragraph = RenderParagraph(
TextSpan(text: _kText, children: <InlineSpan>[ TextSpan(text: _kText, children: <InlineSpan>[
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment