Steps to reproduce
Create a RichText widget with multiple TextSpan or WidgetSpan elements, each representing a clickable link.
Wrap each link in a Semantics widget to ensure accessibility support.
Add GestureDetector to handle onTap events for each link.
Test using a screen reader (TalkBack on Android or VoiceOver on iOS).
Code sample:
MergeSemantics(
child: RichText(
text: TextSpan(
style: const TextStyle(color: Colors.black, fontSize: 16.0),
children: [
const TextSpan(
text:
'Android is a mobile operating system based on a modified version of the ',
),
WidgetSpan(
child: Semantics(
label: 'Linux kernel',
button: true,
//link: true,
child: GestureDetector(
onTap: () {
print("Link 1 tapped!");
},
child: const Text(
'Linux kernel',
style: TextStyle(
color: Colors.blue,
decoration: TextDecoration.underline,
),
),
),
),
),
const TextSpan(
text: ' and other ',
),
WidgetSpan(
child: Semantics(
label: 'open-source',
button: true,
//link: true,
child: GestureDetector(
onTap: () {
print(" link 2 tapped!");
},
child: const Text(
'open-source',
style: TextStyle(
color: Colors.blue,
decoration: TextDecoration.underline,
),
),
),
),
),
const TextSpan(
text: ' software.',
),
],
),
),
Expected results
Whole content should be readable in a single tap and each link should be clickable.
Actual results
The screen reader only selects or announces the first link consistently.
The second link is often skipped or merged with surrounding text, making it inaccessible.
Steps to reproduce
Create a RichText widget with multiple TextSpan or WidgetSpan elements, each representing a clickable link.
Wrap each link in a Semantics widget to ensure accessibility support.
Add GestureDetector to handle onTap events for each link.
Test using a screen reader (TalkBack on Android or VoiceOver on iOS).
Code sample:
MergeSemantics(
child: RichText(
text: TextSpan(
style: const TextStyle(color: Colors.black, fontSize: 16.0),
children: [
const TextSpan(
text:
'Android is a mobile operating system based on a modified version of the ',
),
WidgetSpan(
child: Semantics(
label: 'Linux kernel',
button: true,
//link: true,
child: GestureDetector(
onTap: () {
print("Link 1 tapped!");
},
child: const Text(
'Linux kernel',
style: TextStyle(
color: Colors.blue,
decoration: TextDecoration.underline,
),
),
),
),
),
const TextSpan(
text: ' and other ',
),
WidgetSpan(
child: Semantics(
label: 'open-source',
button: true,
//link: true,
child: GestureDetector(
onTap: () {
print(" link 2 tapped!");
},
child: const Text(
'open-source',
style: TextStyle(
color: Colors.blue,
decoration: TextDecoration.underline,
),
),
),
),
),
const TextSpan(
text: ' software.',
),
],
),
),
Expected results
Whole content should be readable in a single tap and each link should be clickable.
Actual results
The screen reader only selects or announces the first link consistently.
The second link is often skipped or merged with surrounding text, making it inaccessible.
Share Improve this question edited Nov 19, 2024 at 12:10 Nishore kumar asked Nov 19, 2024 at 8:23 Nishore kumarNishore kumar 12 bronze badges1 Answer
Reset to default 0Try using recognizer
in TextSpan
instead of using WidgetSpan
and GestureDetector
MergeSemantics(
child: RichText(
text: TextSpan(
style: const TextStyle(color: Colors.black, fontSize: 16.0),
children: [
const TextSpan(
text:
'Android is a mobile operating system based on a modified version of the ',
),
TextSpan(
text: 'Linux kernel',
recognizer: TapGestureRecognizer()
..onTap = () {
print("Link 1 tapped!");
}),
const TextSpan(
text: ' and other ',
),
TextSpan(
text: 'open-source',
recognizer: TapGestureRecognizer()
..onTap = () {
print(" link 2 tapped!");
}),
const TextSpan(
text: ' software.',
),
],
),
));
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745576176a4633974.html
评论列表(0条)