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
onTapUp: enabled ? _handleTapUp : null,
onTapCancel: enabled ? _handleTapCancel : null,
onTap: widget.onPressed,
child: new Semantics(
button: true,
child: new ConstrainedBox(
constraints: widget.minSize == null
? const BoxConstraints()
......@@ -234,6 +236,7 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv
),
),
),
),
);
}
}
......@@ -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: <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 }) {
......
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