2023-11-14 15:09:03 -07:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2023-11-17 16:17:28 -07:00
|
|
|
import 'package:stripe_native_card_field/card_details.dart';
|
2023-11-14 15:09:03 -07:00
|
|
|
import 'package:stripe_native_card_field/stripe_native_card_field.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
runApp(const MyApp());
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
const MyApp({super.key});
|
|
|
|
|
|
|
|
// This widget is the root of your application.
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
2023-11-21 09:45:25 -07:00
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
title: 'Native Stripe Field Demo',
|
2023-11-14 15:09:03 -07:00
|
|
|
theme: ThemeData(
|
|
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
|
|
|
useMaterial3: true,
|
|
|
|
),
|
|
|
|
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
|
|
const MyHomePage({super.key, required this.title});
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
2023-11-21 09:45:25 -07:00
|
|
|
CardDetailsValidState? state;
|
2023-11-17 16:17:28 -07:00
|
|
|
String? errorText;
|
|
|
|
|
2023-11-14 15:09:03 -07:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
|
|
title: Text(widget.title),
|
|
|
|
),
|
|
|
|
body: Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
2023-11-17 16:17:28 -07:00
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.all(8.0),
|
|
|
|
child: Text(
|
|
|
|
'Enter your card details below:',
|
|
|
|
),
|
2023-11-14 15:09:03 -07:00
|
|
|
),
|
|
|
|
CardTextField(
|
2023-11-21 09:45:25 -07:00
|
|
|
width: 300,
|
|
|
|
onCardDetailsComplete: (details) {
|
|
|
|
if (kDebugMode) {
|
|
|
|
print(details);
|
|
|
|
}
|
2023-11-14 15:09:03 -07:00
|
|
|
},
|
2023-11-21 09:45:25 -07:00
|
|
|
// textStyle: TextStyle(fontSize: 24.0),
|
|
|
|
// cardFieldWidth: 260,
|
|
|
|
// expFieldWidth: 100.0,
|
|
|
|
// securityFieldWidth: 60.0,
|
|
|
|
// postalFieldWidth: 130.0,
|
|
|
|
// iconSize: Size(50.0, 35.0),
|
2023-11-17 16:18:27 -07:00
|
|
|
overrideValidState: state,
|
|
|
|
errorText: errorText,
|
2023-11-14 15:09:03 -07:00
|
|
|
),
|
2023-11-17 16:17:28 -07:00
|
|
|
ElevatedButton(
|
2023-11-17 16:18:27 -07:00
|
|
|
child: const Text('Set manual error'),
|
2023-11-17 16:17:28 -07:00
|
|
|
onPressed: () => setState(() {
|
|
|
|
errorText = 'There is a problem';
|
2023-11-21 09:45:25 -07:00
|
|
|
state = CardDetailsValidState.invalidCard;
|
2023-11-17 16:17:28 -07:00
|
|
|
}),
|
|
|
|
)
|
2023-11-14 15:09:03 -07:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|