0.0.6 release
This commit is contained in:
@@ -61,14 +61,15 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
),
|
||||
CardTextField(
|
||||
width: 300,
|
||||
onCardDetailsComplete: (details) {
|
||||
onValidCardDetails: (details) {
|
||||
if (kDebugMode) {
|
||||
print(details);
|
||||
}
|
||||
},
|
||||
textStyle:
|
||||
const TextStyle(fontFamily: 'Lato', color: Colors.tealAccent),
|
||||
hintTextStyle: const TextStyle(fontFamily: 'Lato', color: Colors.teal),
|
||||
hintTextStyle:
|
||||
const TextStyle(fontFamily: 'Lato', color: Colors.teal),
|
||||
errorTextStyle: const TextStyle(color: Colors.purpleAccent),
|
||||
boxDecoration: BoxDecoration(
|
||||
color: Colors.black54,
|
||||
|
||||
+29
-10
@@ -38,8 +38,26 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
CardDetailsValidState? state;
|
||||
String? errorText;
|
||||
|
||||
// Creating a global key here allows us to call the `getStripeResponse()`
|
||||
// inside the CardTextFieldState widget in our build method. See below
|
||||
final _key = GlobalKey<CardTextFieldState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cardField = CardTextField(
|
||||
key: _key,
|
||||
loadingWidgetLocation: LoadingLocation.above,
|
||||
stripePublishableKey: 'pk_test_abc123testmykey',
|
||||
width: 600,
|
||||
onValidCardDetails: (details) {
|
||||
if (kDebugMode) {
|
||||
print(details);
|
||||
}
|
||||
},
|
||||
overrideValidState: state,
|
||||
errorText: errorText,
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: Column(
|
||||
@@ -51,22 +69,23 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
'Enter your card details below:',
|
||||
),
|
||||
),
|
||||
CardTextField(
|
||||
width: 300,
|
||||
onCardDetailsComplete: (details) {
|
||||
if (kDebugMode) {
|
||||
print(details);
|
||||
}
|
||||
},
|
||||
overrideValidState: state,
|
||||
errorText: errorText,
|
||||
),
|
||||
cardField,
|
||||
ElevatedButton(
|
||||
child: const Text('Set manual error'),
|
||||
onPressed: () => setState(() {
|
||||
errorText = 'There is a problem';
|
||||
state = CardDetailsValidState.invalidCard;
|
||||
}),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
ElevatedButton(
|
||||
child: const Text('Get Stripe token'),
|
||||
onPressed: () async {
|
||||
// Here we use the global key to get the stripe data, rather than
|
||||
// using the `onStripeResponse` callback in the widget
|
||||
final tok = await _key.currentState?.getStripeResponse();
|
||||
if (kDebugMode) print(tok);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
|
||||
@@ -206,7 +206,7 @@ packages:
|
||||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.0.3"
|
||||
version: "0.0.5"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
Reference in New Issue
Block a user