-
-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix platformPayCreatePaymentMethod error (#1882)
Co-authored-by: Eduard Dumitrescu <[email protected]>
- Loading branch information
1 parent
4fbd54f
commit dac2181
Showing
6 changed files
with
101 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
example/lib/screens/wallets/mobile_pay_create_payment_method_screen.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_stripe/flutter_stripe.dart'; | ||
import 'package:stripe_example/widgets/example_scaffold.dart'; | ||
import 'package:stripe_example/widgets/response_card.dart'; | ||
|
||
class MobilePayCreatePaymentMethodScreen extends StatefulWidget { | ||
const MobilePayCreatePaymentMethodScreen({super.key}); | ||
|
||
@override | ||
State<MobilePayCreatePaymentMethodScreen> createState() => | ||
_MobilePayCreatePaymentMethodScreenState(); | ||
} | ||
|
||
class _MobilePayCreatePaymentMethodScreenState | ||
extends State<MobilePayCreatePaymentMethodScreen> { | ||
PlatformPayPaymentMethod? response; | ||
|
||
@override | ||
void initState() { | ||
Stripe.instance.isPlatformPaySupportedListenable.addListener(update); | ||
super.initState(); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
Stripe.instance.isPlatformPaySupportedListenable.removeListener(update); | ||
super.dispose(); | ||
} | ||
|
||
void update() { | ||
setState(() {}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ExampleScaffold( | ||
title: 'Google/Apple Pay', | ||
tags: ['Web'], | ||
padding: EdgeInsets.all(16), | ||
children: [ | ||
if (Stripe.instance.isPlatformPaySupportedListenable.value) | ||
SizedBox( | ||
height: 77, | ||
width: 30, | ||
child: PlatformPayButton( | ||
type: PlatformButtonType.googlePayMark, | ||
onPressed: _handlePayPress, | ||
), | ||
) | ||
else | ||
Text('Google/Apple Pay is not available in this device'), | ||
SizedBox( | ||
height: 50, | ||
), | ||
ResponseCard(response: response?.toString() ?? ''), | ||
], | ||
); | ||
} | ||
|
||
Future<void> _handlePayPress() async { | ||
// 1. create payment method | ||
|
||
final paymentMethod = await Stripe.instance.createPlatformPayPaymentMethod( | ||
params: PlatformPayPaymentMethodParams.web( | ||
options: PlatformPayWebPaymentRequestCreateOptions( | ||
country: 'DE', | ||
currency: 'eur', | ||
total: PlatformPayWebPaymentItem( | ||
amount: 1521, | ||
label: '', | ||
), | ||
), | ||
), | ||
); | ||
|
||
setState(() { | ||
response = paymentMethod; | ||
}); | ||
|
||
ScaffoldMessenger.of(context).showSnackBar(SnackBar( | ||
content: Text( | ||
'Success!: The payment method with id: ${paymentMethod.paymentMethod.id} was created successfully,'))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters