Assertion should allow `semanticsLabel` for TextSpan without `text`

This issue has been created since 2022-11-24.

I don't agree with the following assert:

assert(!(text == null && semanticsLabel != null));

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
exaby73 wrote this answer on 2022-11-25

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 semanticsLabel states:

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?

Albert221 wrote this answer on 2022-11-25

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 children.

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'),
            ],
          )),
        ),
      ),
    );
exaby73 wrote this answer on 2022-11-25

Okay I see your point here. I will label this issue for insights and visibility from the team. Thank you :)

More Details About Repo
Owner Name flutter
Repo Name flutter
Full Name flutter/flutter
Language Dart
Created Date 2015-03-06
Updated Date 2022-12-10
Star Count 147243
Watcher Count 3561
Fork Count 23950
Issue Count 11325

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
[Bug] New service tile when Docker integration is enabled 2 2022-10-10 2022-10-26
Tautulli widget errors 1 2022-10-08 2022-10-26
[Bug] No local favicon with main (94a518f, 8 oct. 2022) 5 2022-10-08 2022-10-26
[Question] Nested object mapping/conversion not working 3 2021-02-19 2022-09-05
Base quality and consensus generation 6 2022-04-06 2022-11-12
Relationships between sections 6 2021-07-14 2022-08-15
Symfony Framework implementation of Porto 0 2022-02-18 2022-08-15
Mention laravel-modules package 1 2021-08-15 2022-08-15
Can actions have other methods? 0 2021-02-10 2022-08-15
Bash scripts location 0 2021-04-09 2022-08-15
Sub-action class declaration and it's place in project structure 1 2021-07-05 2022-08-15
Holo Projector holo (pAI) got killed and can't spawn anymore. 1 2022-10-12 2022-10-24
Volume is way too high 2 2022-05-01 2022-11-02
Can't install sceen2auto 6 2021-11-06 2022-11-06
AAAD download affects headunit? 1 2021-11-16 2022-11-06
Refactor `Cast::build_tx` with Builder pattern 0 2022-03-14 2022-11-12
Restrict panning and rotation of PCL viewer, but allow only clicking 0 2021-11-25 2022-10-20
cannot connect to chrome DevTools HTTP Request failed 2 2022-07-25 2022-10-16
Hugo internal templates not picking up "cover" image for social? 1 2020-09-11 2022-12-01
Acquiring the Homebridge-Magichome GitHub and NPM Name 1 2020-12-03 2022-12-09
Erro de validação no registro C140 1 2021-03-11 2022-12-05
powerjob如何过滤http不安全请求例如TRACE请求 1 2021-12-26 2022-12-06
Remove PayPal adaptive 0 2022-08-30 2022-09-08
Epic: Images list filtering improvements 0 2022-06-16 2022-09-30
Book 1 Section 8.5 distribution scale rate seems incorrect 1 2022-04-02 2022-11-07
CMake and pkg-config files are broken when CMAKE_INSTALL_{BIN,DATAROOT,INCLUDE,LIB}DIR is absolute 0 2022-05-18 2022-10-30
mypy Reports Many Modules without Type Hints or Library Stubs 1 2022-08-30 2022-11-20
KGTK Windows10 Installation error - Module fcntl not found 5 2022-10-10 2022-11-20
Database is locked error in kypher 4 2022-07-05 2022-11-20
Review `kgtk import-ntriples` 0 2022-10-03 2022-11-20
How can I set the compression level to 2, 4, 6 or 8 4 2021-04-10 2022-10-31
[Question] prtconf: devinfo facility not available 3 2020-08-15 2022-12-06
Fuse 3.5 does not run on Mac OS 11.3 and v4.1.0 does not install 3 2021-05-01 2022-12-09
Add adguardhome to the umbrel app store 1 2022-07-16 2022-10-12
Checkpoint system does not work with saving the mass matrix for explicit solvers 0 2022-04-06 2022-05-09
Support for Telegram Bot Revolution (API 6.0) 7 2022-04-20 2022-12-01
Improve the way gas is estimated via the API eth_estimateGas 3 2021-09-27 2022-11-18
Unsupported shell: /bin/csh 0 2022-09-19 2022-11-29
add ability to manage members of an org 1 2021-05-25 2022-11-25
Boats Disappearing on Place 1 2022-02-12 2022-10-29
Use Initializer Lists 1 2021-12-01 2022-10-23
[Enhancement] maybe algo argument can be omitted in cudnn-function? 0 2022-08-05 2022-12-02
Impossible to force literalNum(10.0) to be a double 0 2021-11-05 2022-12-02
Using pipeline library at lachie/jenkins-pipeline 1 2016-11-05 2022-11-03
Interval of Find My Mouse Shortcut 0 2022-08-07 2022-08-06
Not able to write logs into File 1 2022-08-23 2022-11-22
Add information on updating blog posts 11 2022-02-25 2022-12-05
Training loop now working very slow 1 2022-03-25 2022-11-02
Which underlying algorithm does `rolling_hash` use? 6 2021-11-03 2022-11-26
It seems that Oracle has supported EF core 6.0 0 2022-03-25 2022-11-03