Skip to content

Commit bcf73df

Browse files
authored
Add Button Border-Radius for Apple Pay Button (#460)
1 parent ef7164b commit bcf73df

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/stripe/lib/src/widgets/apple_pay_button.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ApplePayButton extends StatelessWidget {
1717
Key? key,
1818
this.style = ApplePayButtonStyle.black,
1919
this.type = ApplePayButtonType.plain,
20+
this.cornerRadius = 4.0,
2021
this.onPressed,
2122
double? width,
2223
double? height = _kApplePayButtonDefaultHeight,
@@ -42,6 +43,11 @@ class ApplePayButton extends StatelessWidget {
4243
/// Default is [ApplePayButtonType.plain].
4344
final ApplePayButtonType type;
4445

46+
/// Modifies the **corner radius** of the payment button.
47+
/// To remove the rounded courners, set this value to 0.0.
48+
/// The default value is set to 4.0
49+
final double cornerRadius;
50+
4551
/// Callback that is executed when the button is pressed.
4652
final VoidCallback? onPressed;
4753

@@ -62,6 +68,7 @@ class ApplePayButton extends StatelessWidget {
6268
return _UiKitApplePayButton(
6369
type: type,
6470
style: style,
71+
cornerRadius: cornerRadius,
6572
onPressed: onPressed,
6673
);
6774
default:
@@ -76,11 +83,13 @@ class _UiKitApplePayButton extends StatefulWidget {
7683
Key? key,
7784
this.style = ApplePayButtonStyle.black,
7885
this.type = ApplePayButtonType.plain,
86+
this.cornerRadius = 4.0,
7987
this.onPressed,
8088
}) : super(key: key);
8189

8290
final ApplePayButtonStyle style;
8391
final ApplePayButtonType type;
92+
final double cornerRadius;
8493
final VoidCallback? onPressed;
8594
@override
8695
_UiKitApplePayButtonState createState() => _UiKitApplePayButtonState();
@@ -97,7 +106,11 @@ class _UiKitApplePayButtonState extends State<_UiKitApplePayButton> {
97106
return UiKitView(
98107
viewType: 'flutter.stripe/apple_pay',
99108
creationParamsCodec: const StandardMessageCodec(),
100-
creationParams: {'type': type, 'style': style},
109+
creationParams: {
110+
'type': type,
111+
'style': style,
112+
'cornerRadius': widget.cornerRadius
113+
},
101114
onPlatformViewCreated: (viewId) {
102115
methodChannel = MethodChannel('flutter.stripe/apple_pay/$viewId');
103116
methodChannel?.setMethodCallHandler((call) async {

packages/stripe_ios/ios/Classes/ApplePayButtonView.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ApplePayButtonView: NSObject, FlutterPlatformView {
3737
private var _view: UIView
3838
var type: NSNumber?
3939
var style: NSNumber?
40+
var cornerRadius: CGFloat = 4.0
4041

4142

4243
private var applePayButton: PKPaymentButton?
@@ -60,6 +61,7 @@ class ApplePayButtonView: NSObject, FlutterPlatformView {
6061
if let arguments = args as? Dictionary<String, AnyObject> {
6162
type = arguments["type"] as? NSNumber
6263
style = arguments["style"] as? NSNumber
64+
cornerRadius = arguments["cornerRadius"] as! CGFloat
6365
}
6466
// iOS views can be created here
6567
createApplePayView()
@@ -74,6 +76,7 @@ class ApplePayButtonView: NSObject, FlutterPlatformView {
7476
if let arguments = call.arguments as? Dictionary<String, AnyObject> {
7577
self.type = arguments["type"] as? NSNumber
7678
self.style = arguments["style"] as? NSNumber
79+
self.cornerRadius = arguments["cornerRadius"] as! CGFloat
7780
}
7881

7982
self.createApplePayView()
@@ -107,6 +110,9 @@ class ApplePayButtonView: NSObject, FlutterPlatformView {
107110
applePayButton.leftAnchor.constraint(equalTo: _view.leftAnchor).isActive = true
108111
applePayButton.rightAnchor.constraint(equalTo: _view.rightAnchor).isActive = true
109112

113+
if #available(iOS 12.0, *) {
114+
applePayButton.cornerRadius = cornerRadius
115+
}
110116
}
111117
}
112118

0 commit comments

Comments
 (0)