Unverified Commit 236ee295 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Create an InlineSpanSemanticsInformation only if the TextSpan has text (#75666)

Fixes https://github.com/flutter/flutter/issues/75622
parent 6db3d61e
...@@ -71,7 +71,8 @@ class TextSpan extends InlineSpan { ...@@ -71,7 +71,8 @@ class TextSpan extends InlineSpan {
TextStyle? style, TextStyle? style,
this.recognizer, this.recognizer,
this.semanticsLabel, this.semanticsLabel,
}) : super(style: style); }) : assert(!(text == null && semanticsLabel != null)),
super(style: style);
/// The text contained in this span. /// The text contained in this span.
/// ///
...@@ -279,7 +280,7 @@ class TextSpan extends InlineSpan { ...@@ -279,7 +280,7 @@ class TextSpan extends InlineSpan {
@override @override
void computeSemanticsInformation(List<InlineSpanSemanticsInformation> collector) { void computeSemanticsInformation(List<InlineSpanSemanticsInformation> collector) {
assert(debugAssertIsValid()); assert(debugAssertIsValid());
if (text != null || semanticsLabel != null) { if (text != null) {
collector.add(InlineSpanSemanticsInformation( collector.add(InlineSpanSemanticsInformation(
text!, text!,
semanticsLabel: semanticsLabel, semanticsLabel: semanticsLabel,
......
...@@ -231,4 +231,11 @@ void main() { ...@@ -231,4 +231,11 @@ void main() {
expect(textSpan.getSpanForPosition(const TextPosition(offset: 2)).runtimeType, WidgetSpan); expect(textSpan.getSpanForPosition(const TextPosition(offset: 2)).runtimeType, WidgetSpan);
expect(textSpan.getSpanForPosition(const TextPosition(offset: 3)).runtimeType, TextSpan); expect(textSpan.getSpanForPosition(const TextPosition(offset: 3)).runtimeType, TextSpan);
}); });
test('TextSpan computeSemanticsInformation', () {
final List<InlineSpanSemanticsInformation> collector = <InlineSpanSemanticsInformation>[];
const TextSpan(text: 'aaa', semanticsLabel: 'bbb').computeSemanticsInformation(collector);
expect(collector[0].text, 'aaa');
expect(collector[0].semanticsLabel, 'bbb');
});
} }
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