Add color to CupertinoButton.filled constructor (#161660)

Issue: https://github.com/flutter/flutter/issues/161590

This pull request adds `color` argument for CupertinoButton.filled
constructor

---------

Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
This commit is contained in:
Jack 2025-02-04 04:36:09 +03:00 committed by GitHub
parent 4bc1994dde
commit 72540c8a1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 5 deletions

View File

@ -131,15 +131,14 @@ class CupertinoButton extends StatefulWidget {
/// Creates an iOS-style button with a filled background.
///
/// The background color is derived from the [CupertinoTheme]'s `primaryColor`.
///
/// To specify a custom background color, use the [color] argument of the
/// default constructor.
/// The background color is derived from the [color] argument.
/// The foreground color is the [CupertinoTheme]'s `primaryContrastingColor`.
const CupertinoButton.filled({
super.key,
required this.child,
this.sizeStyle = CupertinoButtonSize.large,
this.padding,
this.color,
this.disabledColor = CupertinoColors.tertiarySystemFill,
@Deprecated(
'Use minimumSize instead. '
@ -158,7 +157,6 @@ class CupertinoButton extends StatefulWidget {
required this.onPressed,
}) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)),
assert(minimumSize == null || minSize == null),
color = null,
_style = _CupertinoButtonStyle.filled;
/// The widget below this widget in the tree.

View File

@ -595,6 +595,33 @@ void main() {
.decoration
as BoxDecoration;
expect(decoration.color, isSameColorAs(CupertinoColors.systemBlue.darkColor));
await tester.pumpWidget(
CupertinoApp(
home: CupertinoButton.filled(
color: CupertinoColors.systemRed,
onPressed: () {},
child: Builder(
builder: (BuildContext context) {
textStyle = DefaultTextStyle.of(context).style;
return const Placeholder();
},
),
),
),
);
decoration =
tester
.widget<DecoratedBox>(
find.descendant(
of: find.byType(CupertinoButton),
matching: find.byType(DecoratedBox),
),
)
.decoration
as BoxDecoration;
expect(decoration.color, isSameColorAs(CupertinoColors.systemRed));
});
testWidgets("All CupertinoButton const maps keys' match the available style sizes", (