fix slider semantic label (#162304)

Added a `label` argument to the `Semantics` widget which the `Slider`
widget creates. This exposes the `Slider`s label to assistive
technologies so they can stop speaking "Slider".

- Fixes #162067

---------

Co-authored-by: Hannah Jin <jhy03261997@gmail.com>
This commit is contained in:
Chris Norman 2025-01-30 19:03:46 +00:00 committed by GitHub
parent 0444dda508
commit 4619574834
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View File

@ -989,6 +989,7 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
}
return Semantics(
label: widget.label,
container: true,
slider: true,
onDidGainAccessibilityFocus: handleDidGainAccessibilityFocus,

View File

@ -1767,6 +1767,7 @@ void main() {
testWidgets('Slider.label info should not write to semantic node', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
const String label = 'Bingo';
await tester.pumpWidget(
MaterialApp(
home: Directionality(
@ -1778,7 +1779,7 @@ void main() {
divisions: 10,
semanticFormatterCallback: (double value) => value.round().toString(),
onChanged: (double v) {},
label: 'Bingo',
label: label,
),
),
),
@ -1818,6 +1819,7 @@ void main() {
increasedValue: '60',
decreasedValue: '20',
textDirection: TextDirection.ltr,
label: label,
),
],
),