Commit 3365b01f authored by amirh's avatar amirh Committed by GitHub

Add button semantics to CupertinoButton (#12715)

fixes #11992 
parent cbfed196
...@@ -195,6 +195,8 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv ...@@ -195,6 +195,8 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv
onTapUp: enabled ? _handleTapUp : null, onTapUp: enabled ? _handleTapUp : null,
onTapCancel: enabled ? _handleTapCancel : null, onTapCancel: enabled ? _handleTapCancel : null,
onTap: widget.onPressed, onTap: widget.onPressed,
child: new Semantics(
button: true,
child: new ConstrainedBox( child: new ConstrainedBox(
constraints: widget.minSize == null constraints: widget.minSize == null
? const BoxConstraints() ? const BoxConstraints()
...@@ -234,6 +236,7 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv ...@@ -234,6 +236,7 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv
), ),
), ),
), ),
),
); );
} }
} }
...@@ -2,10 +2,15 @@ ...@@ -2,10 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:ui' show SemanticsFlags;
import 'package:flutter/rendering.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../widgets/semantics_tester.dart';
const TextStyle testStyle = const TextStyle( const TextStyle testStyle = const TextStyle(
fontFamily: 'Ahem', fontFamily: 'Ahem',
fontSize: 10.0, fontSize: 10.0,
...@@ -164,6 +169,37 @@ void main() { ...@@ -164,6 +169,37 @@ void main() {
)); ));
expect(opacity.opacity, pressedOpacity); 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: <TestSemantics>[
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 }) { Widget boilerplate({ Widget child }) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment