diff --git a/packages/flutter/lib/src/cupertino/dialog.dart b/packages/flutter/lib/src/cupertino/dialog.dart index a3b876948f..314744ec0e 100644 --- a/packages/flutter/lib/src/cupertino/dialog.dart +++ b/packages/flutter/lib/src/cupertino/dialog.dart @@ -10,6 +10,7 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'colors.dart'; +import 'localizations.dart'; import 'scrollbar.dart'; // TODO(abarth): These constants probably belong somewhere more general. @@ -218,6 +219,8 @@ class CupertinoAlertDialog extends StatelessWidget { @override Widget build(BuildContext context) { + final CupertinoLocalizations localizations = CupertinoLocalizations.of(context) + ?? const DefaultCupertinoLocalizations(); final bool isInAccessibilityMode = _isInAccessibilityMode(context); final double textScaleFactor = MediaQuery.of(context).textScaleFactor; return new MediaQuery( @@ -235,9 +238,15 @@ class CupertinoAlertDialog extends StatelessWidget { : _kCupertinoDialogWidth, child: new CupertinoPopupSurface( isSurfacePainted: false, - child: new _CupertinoDialogRenderWidget( - contentSection: _buildContent(), - actionsSection: _buildActions(), + child: new Semantics( + namesRoute: true, + scopesRoute: true, + explicitChildNodes: true, + label: localizations.alertDialogLabel, + child: new _CupertinoDialogRenderWidget( + contentSection: _buildContent(), + actionsSection: _buildActions(), + ), ), ), ), @@ -949,18 +958,21 @@ class _PressableActionButtonState extends State<_PressableActionButton> { Widget build(BuildContext context) { return new _ActionButtonParentDataWidget( isPressed: _isPressed, - // TODO(mattcarroll): Button press dynamics need overhaul for iOS: https://github.com/flutter/flutter/issues/19786 - child: new GestureDetector( - behavior: HitTestBehavior.opaque, - onTapDown: (TapDownDetails details) => setState(() { - _isPressed = true; - }), - onTapUp: (TapUpDetails details) => setState(() { - _isPressed = false; - }), - // TODO(mattcarroll): Cancel is currently triggered when user moves past slop instead of off button: https://github.com/flutter/flutter/issues/19783 - onTapCancel: () => setState(() => _isPressed = false), - child: widget.child, + child: new MergeSemantics( + // TODO(mattcarroll): Button press dynamics need overhaul for iOS: https://github.com/flutter/flutter/issues/19786 + child: new GestureDetector( + excludeFromSemantics: true, + behavior: HitTestBehavior.opaque, + onTapDown: (TapDownDetails details) => setState(() { + _isPressed = true; + }), + onTapUp: (TapUpDetails details) => setState(() { + _isPressed = false; + }), + // TODO(mattcarroll): Cancel is currently triggered when user moves past slop instead of off button: https://github.com/flutter/flutter/issues/19783 + onTapCancel: () => setState(() => _isPressed = false), + child: widget.child, + ), ), ); } @@ -1091,12 +1103,16 @@ class CupertinoDialogAction extends StatelessWidget { constraints: new BoxConstraints( maxWidth: fontSizeRatio * (dialogWidth - (2 * padding)), ), - child: new DefaultTextStyle( - style: textStyle, - textAlign: TextAlign.center, - overflow: TextOverflow.ellipsis, - maxLines: 1, - child: content, + child: new Semantics( + button: true, + onTap: onPressed, + child: new DefaultTextStyle( + style: textStyle, + textAlign: TextAlign.center, + overflow: TextOverflow.ellipsis, + maxLines: 1, + child: content, + ), ), ), ), @@ -1149,6 +1165,7 @@ class CupertinoDialogAction extends StatelessWidget { ); return new GestureDetector( + excludeFromSemantics: true, onTap: onPressed, behavior: HitTestBehavior.opaque, child: new ConstrainedBox( diff --git a/packages/flutter/lib/src/cupertino/localizations.dart b/packages/flutter/lib/src/cupertino/localizations.dart index 8f60a3dade..0d231766bf 100644 --- a/packages/flutter/lib/src/cupertino/localizations.dart +++ b/packages/flutter/lib/src/cupertino/localizations.dart @@ -80,6 +80,9 @@ abstract class CupertinoLocalizations { /// The abbreviation for post meridiem (after noon) shown in the time picker. String get postMeridiemAbbreviation; + /// The term used by the system to announce dialog alerts. + String get alertDialogLabel; + /// Hour that is shown in [CupertinoCountdownTimerPicker] corresponding to /// the given hour value. /// @@ -232,6 +235,9 @@ class DefaultCupertinoLocalizations implements CupertinoLocalizations { @override String get postMeridiemAbbreviation => 'PM'; + @override + String get alertDialogLabel => 'Alert'; + @override String timerPickerHour(int hour) => hour.toString(); diff --git a/packages/flutter/test/cupertino/dialog_test.dart b/packages/flutter/test/cupertino/dialog_test.dart index a1f11db2b6..b60e4ce840 100644 --- a/packages/flutter/test/cupertino/dialog_test.dart +++ b/packages/flutter/test/cupertino/dialog_test.dart @@ -10,6 +10,7 @@ import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import '../rendering/mock_canvas.dart'; +import '../widgets/semantics_tester.dart'; void main() { testWidgets('Alert dialog control test', (WidgetTester tester) async { @@ -63,6 +64,68 @@ void main() { expect(widget.style.color.alpha, lessThan(255)); }); + testWidgets('Has semantic annotations', (WidgetTester tester) async { + final SemanticsTester semantics = new SemanticsTester(tester); + await tester.pumpWidget(MaterialApp(home: const Material( + child: CupertinoAlertDialog( + title: Text('The Title'), + content: Text('Content'), + actions: [ + CupertinoDialogAction(child: Text('Cancel')), + CupertinoDialogAction(child: Text('OK')), + ], + ) + ))); + + expect( + semantics, + hasSemantics( + new TestSemantics.root( + children: [ + new TestSemantics( + children: [ + new TestSemantics( + flags: [SemanticsFlag.scopesRoute], + children: [ + new TestSemantics( + flags: [SemanticsFlag.scopesRoute, SemanticsFlag.namesRoute], + label: 'Alert', + children: [ + new TestSemantics( + children: [ + new TestSemantics(label: 'The Title'), + new TestSemantics(label: 'Content'), + ], + ), + new TestSemantics( + children: [ + new TestSemantics( + flags: [SemanticsFlag.isButton], + label: 'Cancel', + ), + new TestSemantics( + flags: [SemanticsFlag.isButton], + label: 'OK', + ), + ], + ), + ], + ), + ], + ), + ], + ), + ], + ), + ignoreId: true, + ignoreRect: true, + ignoreTransform: true, + ) + ); + + semantics.dispose(); + }); + testWidgets('Dialog default action styles', (WidgetTester tester) async { await tester.pumpWidget(boilerplate(const CupertinoDialogAction( isDefaultAction: true,