Skip to content

Commit

Permalink
Make _UiKitApplePayButton stateful
Browse files Browse the repository at this point in the history
  • Loading branch information
dickermoshe authored and JlUgia committed Jan 21, 2024
1 parent 576fabe commit 42479dd
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pay_ios/lib/src/widgets/apple_pay_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class RawApplePayButton extends StatelessWidget {
}

/// A widget to draw the Apple Pay button through a [PlatforView].
class _UiKitApplePayButton extends StatelessWidget {
class _UiKitApplePayButton extends StatefulWidget {
static const buttonId = 'plugins.flutter.io/pay/apple_pay_button';

final VoidCallback? onPressed;
Expand All @@ -145,16 +145,21 @@ class _UiKitApplePayButton extends StatelessWidget {
this.type = ApplePayButtonType.plain,
});

@override
State<_UiKitApplePayButton> createState() => _UiKitApplePayButtonState();
}

class _UiKitApplePayButtonState extends State<_UiKitApplePayButton> {
@override
Widget build(BuildContext context) {
return UiKitView(
viewType: buttonId,
viewType: _UiKitApplePayButton.buttonId,
creationParamsCodec: const StandardMessageCodec(),
creationParams: {'style': style.enumString, 'type': type.enumString},
creationParams: {'style': widget.style.enumString, 'type': widget.type.enumString},
onPlatformViewCreated: (viewId) {
MethodChannel methodChannel = MethodChannel('$buttonId/$viewId');
MethodChannel methodChannel = MethodChannel('${_UiKitApplePayButton.buttonId}/$viewId');
methodChannel.setMethodCallHandler((call) async {
if (call.method == 'onPressed') onPressed?.call();
if (call.method == 'onPressed') widget.onPressed?.call();
});
},
);
Expand Down

0 comments on commit 42479dd

Please sign in to comment.