parent
cbfed1960f
commit
3365b01f9a
@ -195,39 +195,42 @@ class _CupertinoButtonState extends State<CupertinoButton> 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,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -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 }) {
|
||||
@ -171,4 +207,4 @@ Widget boilerplate({ Widget child }) {
|
||||
textDirection: TextDirection.ltr,
|
||||
child: new Center(child: child),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user