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

Fixes https://github.com/flutter/flutter/issues/75622
This commit is contained in:
Jason Simmons 2021-02-11 11:46:18 -08:00 committed by GitHub
parent 6db3d61ed4
commit 236ee295bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -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,

View File

@ -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');
});
}