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 {
TextStyle? style,
this.recognizer,
this.semanticsLabel,
}) : super(style: style);
}) : assert(!(text == null && semanticsLabel != null)),
super(style: style);
/// The text contained in this span.
///
......@@ -279,7 +280,7 @@ class TextSpan extends InlineSpan {
@override
void computeSemanticsInformation(List<InlineSpanSemanticsInformation> collector) {
assert(debugAssertIsValid());
if (text != null || semanticsLabel != null) {
if (text != null) {
collector.add(InlineSpanSemanticsInformation(
text!,
semanticsLabel: semanticsLabel,
......
......@@ -231,4 +231,11 @@ void main() {
expect(textSpan.getSpanForPosition(const TextPosition(offset: 2)).runtimeType, WidgetSpan);
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