I don't agree with the following assert:
Let's say I'm constructing a rich text with a root
TextSpan consisting of a few
TextSpans and (decorative - say - icons)
WidgetSpans in its
children. And I also want to provide universal
semanticsLabel for the whole text, that gives better meaning to screen reader users.
Flutter 3.3.5 • channel stable • https://github.com/flutter/flutter.git Framework • revision d9111f6402 (5 weeks ago) • 2022-10-19 12:27:13 -0700 Engine • revision 3ad69d7be3 Tools • Dart 2.18.2 • DevTools 2.15.0
Hello @Albert221. Help me understand your use case. The assertion says that you shouldn't have an empty
TextSpan.text and also an empty
semanticsLabel. The documentation for
If present, the semantics of this span will contain this value instead of the actual text.
This is useful for replacing abbreviations or shorthands with the full text value:
Could you provide a code sample where the current behavior is undesirable and/or throws an assertion error during development?
Hi @exaby73, thanks for your response!
Actually, the assertion says that I cannot have
semanticsLabel when I don't have
text => I cannot have
semanticsLabel when I have
Here's a quick example with failing assert:
import 'package:flutter/material.dart'; void main() => runApp( MaterialApp( home: Scaffold( body: Text.rich(TextSpan( children: [ TextSpan( children: const [ WidgetSpan(child: SizedBox()), // Some unread indicator TextSpan(text: 'Notifications'), TextSpan(text: '(1)'), ], semanticsLabel: '1 new notification', ), const TextSpan(text: 'Something else'), ], )), ), ), );
|Issue Title||Created Date||Updated Date|