Skip to content

Commit 72540c8

Browse files
Add color to CupertinoButton.filled constructor (#161660)
Issue: flutter/flutter#161590 This pull request adds `color` argument for CupertinoButton.filled constructor --------- Co-authored-by: Tong Mu <[email protected]>
1 parent 4bc1994 commit 72540c8

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

packages/flutter/lib/src/cupertino/button.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,14 @@ class CupertinoButton extends StatefulWidget {
131131

132132
/// Creates an iOS-style button with a filled background.
133133
///
134-
/// The background color is derived from the [CupertinoTheme]'s `primaryColor`.
135-
///
136-
/// To specify a custom background color, use the [color] argument of the
137-
/// default constructor.
134+
/// The background color is derived from the [color] argument.
135+
/// The foreground color is the [CupertinoTheme]'s `primaryContrastingColor`.
138136
const CupertinoButton.filled({
139137
super.key,
140138
required this.child,
141139
this.sizeStyle = CupertinoButtonSize.large,
142140
this.padding,
141+
this.color,
143142
this.disabledColor = CupertinoColors.tertiarySystemFill,
144143
@Deprecated(
145144
'Use minimumSize instead. '
@@ -158,7 +157,6 @@ class CupertinoButton extends StatefulWidget {
158157
required this.onPressed,
159158
}) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)),
160159
assert(minimumSize == null || minSize == null),
161-
color = null,
162160
_style = _CupertinoButtonStyle.filled;
163161

164162
/// The widget below this widget in the tree.

packages/flutter/test/cupertino/button_test.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,33 @@ void main() {
595595
.decoration
596596
as BoxDecoration;
597597
expect(decoration.color, isSameColorAs(CupertinoColors.systemBlue.darkColor));
598+
599+
await tester.pumpWidget(
600+
CupertinoApp(
601+
home: CupertinoButton.filled(
602+
color: CupertinoColors.systemRed,
603+
onPressed: () {},
604+
child: Builder(
605+
builder: (BuildContext context) {
606+
textStyle = DefaultTextStyle.of(context).style;
607+
return const Placeholder();
608+
},
609+
),
610+
),
611+
),
612+
);
613+
614+
decoration =
615+
tester
616+
.widget<DecoratedBox>(
617+
find.descendant(
618+
of: find.byType(CupertinoButton),
619+
matching: find.byType(DecoratedBox),
620+
),
621+
)
622+
.decoration
623+
as BoxDecoration;
624+
expect(decoration.color, isSameColorAs(CupertinoColors.systemRed));
598625
});
599626

600627
testWidgets("All CupertinoButton const maps keys' match the available style sizes", (

0 commit comments

Comments
 (0)