diff --git a/packages/flutter/lib/src/cupertino/button.dart b/packages/flutter/lib/src/cupertino/button.dart index 2fa9e83ed2..b3b15755f6 100644 --- a/packages/flutter/lib/src/cupertino/button.dart +++ b/packages/flutter/lib/src/cupertino/button.dart @@ -195,39 +195,42 @@ class _CupertinoButtonState extends State with SingleTickerProv onTapUp: enabled ? _handleTapUp : null, onTapCancel: enabled ? _handleTapCancel : null, onTap: widget.onPressed, - child: new ConstrainedBox( - constraints: widget.minSize == null - ? const BoxConstraints() - : new BoxConstraints( - minWidth: widget.minSize, - minHeight: widget.minSize, - ), - child: new FadeTransition( - opacity: _opacityTween.animate(new CurvedAnimation( - parent: _animationController, - curve: Curves.decelerate, - )), - child: new DecoratedBox( - decoration: new BoxDecoration( - borderRadius: widget.borderRadius, - color: backgroundColor != null && !enabled - ? _kDisabledBackground - : backgroundColor, - ), - child: new Padding( - padding: widget.padding ?? (backgroundColor != null - ? _kBackgroundButtonPadding - : _kButtonPadding), - child: new Center( - widthFactor: 1.0, - heightFactor: 1.0, - child: new DefaultTextStyle( - style: backgroundColor != null - ? _kBackgroundButtonTextStyle - : enabled - ? _kButtonTextStyle - : _kDisabledButtonTextStyle, - child: widget.child, + child: new Semantics( + button: true, + child: new ConstrainedBox( + constraints: widget.minSize == null + ? const BoxConstraints() + : new BoxConstraints( + minWidth: widget.minSize, + minHeight: widget.minSize, + ), + child: new FadeTransition( + opacity: _opacityTween.animate(new CurvedAnimation( + parent: _animationController, + curve: Curves.decelerate, + )), + child: new DecoratedBox( + decoration: new BoxDecoration( + borderRadius: widget.borderRadius, + color: backgroundColor != null && !enabled + ? _kDisabledBackground + : backgroundColor, + ), + child: new Padding( + padding: widget.padding ?? (backgroundColor != null + ? _kBackgroundButtonPadding + : _kButtonPadding), + child: new Center( + widthFactor: 1.0, + heightFactor: 1.0, + child: new DefaultTextStyle( + style: backgroundColor != null + ? _kBackgroundButtonTextStyle + : enabled + ? _kButtonTextStyle + : _kDisabledButtonTextStyle, + child: widget.child, + ), ), ), ), diff --git a/packages/flutter/test/cupertino/button_test.dart b/packages/flutter/test/cupertino/button_test.dart index 7926e1d08b..a6f24ed032 100644 --- a/packages/flutter/test/cupertino/button_test.dart +++ b/packages/flutter/test/cupertino/button_test.dart @@ -2,10 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:ui' show SemanticsFlags; + +import 'package:flutter/rendering.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter_test/flutter_test.dart'; +import '../widgets/semantics_tester.dart'; + const TextStyle testStyle = const TextStyle( fontFamily: 'Ahem', fontSize: 10.0, @@ -164,6 +169,37 @@ void main() { )); expect(opacity.opacity, pressedOpacity); }); + + testWidgets('Cupertino button is semantically a button', (WidgetTester tester) async { + final SemanticsTester semantics = new SemanticsTester(tester); + await tester.pumpWidget( + boilerplate( + child: new Center( + child: new CupertinoButton( + onPressed: () { }, + child: const Text('ABC') + ), + ), + ), + ); + + expect(semantics, hasSemantics( + new TestSemantics.root( + children: [ + new TestSemantics.rootChild( + actions: SemanticsAction.tap.index, + label: 'ABC', + flags: SemanticsFlags.isButton.index, + ) + ], + ), + ignoreId: true, + ignoreRect: true, + ignoreTransform: true, + )); + + semantics.dispose(); + }); } Widget boilerplate({ Widget child }) { @@ -171,4 +207,4 @@ Widget boilerplate({ Widget child }) { textDirection: TextDirection.ltr, child: new Center(child: child), ); -} \ No newline at end of file +}