'Allow accessibility screen reader to read a number string one-by-one as digits using semantics [flutter]

I'm using Semantics to adapt my app for accessibility and want to read a phone number (like: Text("950874123")) one to one instead "million, thousand...". Is there any way to do it?



Solution 1:[1]

I see this was asked a while back, but I ran into the same problem. I'm adding my solution here to help out the next guy.

I got the solution with the help of this page: https://medium.com/theotherdev-s/mastering-flutter-semantics-672440bc8bc8

Basically, my solution is to use the Semantics label (that I can control) and use ExcludeSemantics to exclude the text that I'm reading. In the label, I divide everything up into an array that I convert into a string. This makes the screen reader see everything as individual numbers.

Here's an example

Semantics(
   label: numberString.split("").toString(),
      child: ExcludeSemantics(
         excluding: true,
            child: Text(numberString),          
             )
 )

*Edit: After playing around more with the code, I realized that the Text field has a property called "semanticsLabel" where you can do the same thing. I left the above example since it can be used for other widget types, not just Text()

This is what the code would look like:

Semantics(
   child: Text(
      viewModel.confirmationId,
      semanticsLabel:numberString.split("").toString(),
    )
)

(additionally, the parent 'Semantics' widget probably isn't needed. The label will work directly with the Text widget)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1