admin管理员组文章数量:1022670
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.',
),
],
),
));
}
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.',
),
],
),
));
}
本文标签: Accessibility Issue Multiple Links on Same Line in Flutter RichTextStack Overflow
版权声明:本文标题:Accessibility Issue: Multiple Links on Same Line in Flutter RichText - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745576175a2157029.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论