mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Create an InlineSpanSemanticsInformation only if the TextSpan has text (#75666)
Fixes https://github.com/flutter/flutter/issues/75622
This commit is contained in:
parent
6db3d61ed4
commit
236ee295bd
@ -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');
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user