diff --git a/packages/flutter/lib/src/cupertino/checkbox.dart b/packages/flutter/lib/src/cupertino/checkbox.dart index 9eaf17a152..3c84615a90 100644 --- a/packages/flutter/lib/src/cupertino/checkbox.dart +++ b/packages/flutter/lib/src/cupertino/checkbox.dart @@ -81,6 +81,7 @@ class CupertinoCheckbox extends StatefulWidget { this.autofocus = false, this.side, this.shape, + this.semanticLabel, }) : assert(tristate || value != null); /// Whether this checkbox is checked. @@ -171,6 +172,13 @@ class CupertinoCheckbox extends StatefulWidget { /// [RoundedRectangleBorder] with a circular corner radius of 4.0. final OutlinedBorder? shape; + /// The semantic label for the checkbox that will be announced by screen readers. + /// + /// This is announced by assistive technologies (e.g TalkBack/VoiceOver). + /// + /// This label does not show in the UI. + final String? semanticLabel; + /// The width of a checkbox widget. static const double width = 18.0; @@ -238,6 +246,7 @@ class _CupertinoCheckboxState extends State with TickerProvid ?? CupertinoColors.white; return Semantics( + label: widget.semanticLabel, checked: widget.value ?? false, mixed: widget.tristate ? widget.value == null : null, child: buildToggleable( diff --git a/packages/flutter/lib/src/material/animated_icons/animated_icons.dart b/packages/flutter/lib/src/material/animated_icons/animated_icons.dart index 09feb5eced..9355f3af38 100644 --- a/packages/flutter/lib/src/material/animated_icons/animated_icons.dart +++ b/packages/flutter/lib/src/material/animated_icons/animated_icons.dart @@ -77,7 +77,7 @@ class AnimatedIcon extends StatelessWidget { /// Semantic label for the icon. /// - /// Announced in accessibility modes (e.g TalkBack/VoiceOver). + /// Announced by assistive technologies (e.g TalkBack/VoiceOver). /// This label does not show in the UI. /// /// See also: diff --git a/packages/flutter/lib/src/material/checkbox.dart b/packages/flutter/lib/src/material/checkbox.dart index 1893eb033b..b62119a10c 100644 --- a/packages/flutter/lib/src/material/checkbox.dart +++ b/packages/flutter/lib/src/material/checkbox.dart @@ -394,7 +394,7 @@ class Checkbox extends StatefulWidget { /// {@template flutter.material.checkbox.semanticLabel} /// The semantic label for the checkbox that will be announced by screen readers. /// - /// This is announced in accessibility modes (e.g TalkBack/VoiceOver). + /// This is announced by assistive technologies (e.g TalkBack/VoiceOver). /// /// This label does not show in the UI. /// {@endtemplate} @@ -495,6 +495,7 @@ class _CheckboxState extends State with TickerProviderStateMixin, Togg autofocus: widget.autofocus, side: widget.side, shape: widget.shape, + semanticLabel: widget.semanticLabel, ); } } diff --git a/packages/flutter/lib/src/widgets/icon.dart b/packages/flutter/lib/src/widgets/icon.dart index b6944fb5e9..728e4a7292 100644 --- a/packages/flutter/lib/src/widgets/icon.dart +++ b/packages/flutter/lib/src/widgets/icon.dart @@ -209,7 +209,7 @@ class Icon extends StatelessWidget { /// Semantic label for the icon. /// - /// Announced in accessibility modes (e.g TalkBack/VoiceOver). + /// Announced by assistive technologies (e.g TalkBack/VoiceOver). /// This label does not show in the UI. /// /// * [SemanticsProperties.label], which is set to [semanticLabel] in the diff --git a/packages/flutter/lib/src/widgets/image_icon.dart b/packages/flutter/lib/src/widgets/image_icon.dart index af19497f18..f8939cda62 100644 --- a/packages/flutter/lib/src/widgets/image_icon.dart +++ b/packages/flutter/lib/src/widgets/image_icon.dart @@ -57,7 +57,7 @@ class ImageIcon extends StatelessWidget { /// Semantic label for the icon. /// - /// Announced in accessibility modes (e.g TalkBack/VoiceOver). + /// Announced by assistive technologies (e.g TalkBack/VoiceOver). /// This label does not show in the UI. /// /// * [SemanticsProperties.label], which is set to [semanticLabel] in the diff --git a/packages/flutter/test/cupertino/checkbox_test.dart b/packages/flutter/test/cupertino/checkbox_test.dart index d3cafe524f..fbe0fe7355 100644 --- a/packages/flutter/test/cupertino/checkbox_test.dart +++ b/packages/flutter/test/cupertino/checkbox_test.dart @@ -338,6 +338,58 @@ void main() { semanticsTester.dispose(); }); + testWidgets('Checkbox can configure a semantic label', (WidgetTester tester) async { + final SemanticsHandle handle = tester.ensureSemantics(); + + await tester.pumpWidget( + CupertinoApp ( + home: Center( + child: CupertinoCheckbox( + value: false, + onChanged: (bool? b) { }, + semanticLabel: 'checkbox', + ), + ), + ), + ); + expect(tester.getSemantics(find.byType(Focus).last), matchesSemantics( + hasCheckedState: true, + hasEnabledState: true, + isEnabled: true, + hasTapAction: true, + hasFocusAction: true, + isFocusable: true, + label: 'checkbox' + )); + + // If wrapped with semantics, both the parent semantic label and the + // checkbox's semantic label are used in annotation. + await tester.pumpWidget( + CupertinoApp( + home: Semantics( + label: 'foo', + textDirection: TextDirection.ltr, + child: CupertinoCheckbox( + value: false, + onChanged: (bool? b) { }, + semanticLabel: 'checkbox', + ), + ), + ), + ); + expect(tester.getSemantics(find.byType(Focus).last), matchesSemantics( + label: 'foo\ncheckbox', + textDirection: TextDirection.ltr, + hasCheckedState: true, + hasEnabledState: true, + isEnabled: true, + hasTapAction: true, + hasFocusAction: true, + isFocusable: true, + )); + handle.dispose(); + }); + testWidgets('Checkbox can be toggled by keyboard shortcuts', (WidgetTester tester) async { tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; bool? value = true;