Unverified Commit 5c8d7e34 authored by xster's avatar xster Committed by GitHub

Adjust Cupertino controls's APIs to match Material (#19127)

parent d3ad0729
...@@ -50,6 +50,7 @@ class CupertinoButton extends StatefulWidget { ...@@ -50,6 +50,7 @@ class CupertinoButton extends StatefulWidget {
@required this.child, @required this.child,
this.padding, this.padding,
this.color, this.color,
this.disabledColor,
this.minSize = 44.0, this.minSize = 44.0,
this.pressedOpacity = 0.1, this.pressedOpacity = 0.1,
this.borderRadius = const BorderRadius.all(const Radius.circular(8.0)), this.borderRadius = const BorderRadius.all(const Radius.circular(8.0)),
...@@ -71,6 +72,14 @@ class CupertinoButton extends StatefulWidget { ...@@ -71,6 +72,14 @@ class CupertinoButton extends StatefulWidget {
/// Defaults to null which produces a button with no background or border. /// Defaults to null which produces a button with no background or border.
final Color color; final Color color;
/// The color of the button's background when the button is disabled.
///
/// Ignored if the [CupertinoButton] doesn't also have a [color].
///
/// Defaults to a standard iOS disabled color when [color] is specified and
/// [disabledColor] is null.
final Color disabledColor;
/// The callback that is called when the button is tapped or otherwise activated. /// The callback that is called when the button is tapped or otherwise activated.
/// ///
/// If this is set to null, the button will be disabled. /// If this is set to null, the button will be disabled.
...@@ -216,7 +225,7 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv ...@@ -216,7 +225,7 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv
decoration: new BoxDecoration( decoration: new BoxDecoration(
borderRadius: widget.borderRadius, borderRadius: widget.borderRadius,
color: backgroundColor != null && !enabled color: backgroundColor != null && !enabled
? _kDisabledBackground ? widget.disabledColor ?? _kDisabledBackground
: backgroundColor, : backgroundColor,
), ),
child: new Padding( child: new Padding(
......
...@@ -57,7 +57,7 @@ class CupertinoSlider extends StatefulWidget { ...@@ -57,7 +57,7 @@ class CupertinoSlider extends StatefulWidget {
this.min = 0.0, this.min = 0.0,
this.max = 1.0, this.max = 1.0,
this.divisions, this.divisions,
this.activeColor = CupertinoColors.activeBlue, this.activeColor,
}) : assert(value != null), }) : assert(value != null),
assert(min != null), assert(min != null),
assert(max != null), assert(max != null),
...@@ -95,7 +95,7 @@ class CupertinoSlider extends StatefulWidget { ...@@ -95,7 +95,7 @@ class CupertinoSlider extends StatefulWidget {
/// }, /// },
/// ) /// )
/// ``` /// ```
/// ///
/// See also: /// See also:
/// ///
/// * [onChangeStart] for a callback that is called when the user starts /// * [onChangeStart] for a callback that is called when the user starts
...@@ -185,6 +185,8 @@ class CupertinoSlider extends StatefulWidget { ...@@ -185,6 +185,8 @@ class CupertinoSlider extends StatefulWidget {
final int divisions; final int divisions;
/// The color to use for the portion of the slider that has been selected. /// The color to use for the portion of the slider that has been selected.
///
/// Defaults to [CupertinoColors.activeBlue].
final Color activeColor; final Color activeColor;
@override @override
...@@ -223,7 +225,7 @@ class _CupertinoSliderState extends State<CupertinoSlider> with TickerProviderSt ...@@ -223,7 +225,7 @@ class _CupertinoSliderState extends State<CupertinoSlider> with TickerProviderSt
return new _CupertinoSliderRenderObjectWidget( return new _CupertinoSliderRenderObjectWidget(
value: (widget.value - widget.min) / (widget.max - widget.min), value: (widget.value - widget.min) / (widget.max - widget.min),
divisions: widget.divisions, divisions: widget.divisions,
activeColor: widget.activeColor, activeColor: widget.activeColor ?? CupertinoColors.activeBlue,
onChanged: widget.onChanged != null ? _handleChanged : null, onChanged: widget.onChanged != null ? _handleChanged : null,
onChangeStart: widget.onChangeStart != null ? _handleDragStart : null, onChangeStart: widget.onChangeStart != null ? _handleDragStart : null,
onChangeEnd: widget.onChangeEnd != null ? _handleDragEnd : null, onChangeEnd: widget.onChangeEnd != null ? _handleDragEnd : null,
......
...@@ -51,7 +51,7 @@ class CupertinoSwitch extends StatefulWidget { ...@@ -51,7 +51,7 @@ class CupertinoSwitch extends StatefulWidget {
Key key, Key key,
@required this.value, @required this.value,
@required this.onChanged, @required this.onChanged,
this.activeColor = CupertinoColors.activeGreen, this.activeColor,
}) : super(key: key); }) : super(key: key);
/// Whether this switch is on or off. /// Whether this switch is on or off.
...@@ -82,6 +82,8 @@ class CupertinoSwitch extends StatefulWidget { ...@@ -82,6 +82,8 @@ class CupertinoSwitch extends StatefulWidget {
final ValueChanged<bool> onChanged; final ValueChanged<bool> onChanged;
/// The color to use when this switch is on. /// The color to use when this switch is on.
///
/// Defaults to [CupertinoColors.activeGreen].
final Color activeColor; final Color activeColor;
@override @override
...@@ -100,7 +102,7 @@ class _CupertinoSwitchState extends State<CupertinoSwitch> with TickerProviderSt ...@@ -100,7 +102,7 @@ class _CupertinoSwitchState extends State<CupertinoSwitch> with TickerProviderSt
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new _CupertinoSwitchRenderObjectWidget( return new _CupertinoSwitchRenderObjectWidget(
value: widget.value, value: widget.value,
activeColor: widget.activeColor, activeColor: widget.activeColor ?? CupertinoColors.activeGreen,
onChanged: widget.onChanged, onChanged: widget.onChanged,
vsync: this, vsync: this,
); );
......
...@@ -198,6 +198,34 @@ void main() { ...@@ -198,6 +198,34 @@ void main() {
semantics.dispose(); semantics.dispose();
}); });
testWidgets('Can specify colors', (WidgetTester tester) async {
await tester.pumpWidget(boilerplate(child: new CupertinoButton(
child: const Text('Skeuomorph me'),
color: const Color(0x0000FF),
disabledColor: const Color(0x00FF00),
onPressed: () { },
)));
BoxDecoration boxDecoration = tester.widget<DecoratedBox>(
find.widgetWithText(DecoratedBox, 'Skeuomorph me')
).decoration;
expect(boxDecoration.color, const Color(0x0000FF));
await tester.pumpWidget(boilerplate(child: const CupertinoButton(
child: const Text('Skeuomorph me'),
color: const Color(0x0000FF),
disabledColor: const Color(0x00FF00),
onPressed: null,
)));
boxDecoration = tester.widget<DecoratedBox>(
find.widgetWithText(DecoratedBox, 'Skeuomorph me')
).decoration;
expect(boxDecoration.color, const Color(0x00FF00));
});
} }
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