Fix empty textspan with spell out crashes (#88738)
This commit is contained in:
@@ -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: <ui.StringAttribute>[
|
||||
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,
|
||||
|
||||
@@ -749,6 +749,18 @@ void main() {
|
||||
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', () {
|
||||
final RenderParagraph paragraph = RenderParagraph(
|
||||
TextSpan(text: _kText, children: <InlineSpan>[
|
||||
|
||||
Reference in New Issue
Block a user