awesome_card 1.1.5 awesome_card: ^1.1.5 copied to clipboard
Flutter package to create a Credit Card Widget in your application.
import 'package:flutter/material.dart';
import 'package:awesome_card/awesome_card.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Awesome Credit Card Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Awesome Credit Card Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String cardNumber = '';
String cardHolderName = '';
String expiryDate = '';
String cvv = '';
bool showBack = false;
late FocusNode _focusNode;
@override
void initState() {
super.initState();
_focusNode = FocusNode();
_focusNode.addListener(() {
setState(() {
_focusNode.hasFocus ? showBack = true : showBack = false;
});
});
}
@override
void dispose() {
_focusNode.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 40,
),
CreditCard(
cardNumber: cardNumber,
cardExpiry: expiryDate,
cardHolderName: cardHolderName,
cvv: cvv,
bankName: 'Axis Bank',
showBackSide: showBack,
frontBackground: CardBackgrounds.black,
backBackground: CardBackgrounds.white,
showShadow: true,
),
SizedBox(
height: 40,
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(
horizontal: 20,
),
child: TextFormField(
decoration: InputDecoration(hintText: 'Card Number'),
maxLength: 19,
onChanged: (value) {
setState(() {
cardNumber = value;
});
},
),
),
Container(
margin: EdgeInsets.symmetric(
horizontal: 20,
),
child: TextFormField(
decoration: InputDecoration(hintText: 'Card Expiry'),
maxLength: 5,
onChanged: (value) {
setState(() {
expiryDate = value;
});
},
),
),
Container(
margin: EdgeInsets.symmetric(
horizontal: 20,
),
child: TextFormField(
decoration: InputDecoration(hintText: 'Card Holder Name'),
onChanged: (value) {
setState(() {
cardHolderName = value;
});
},
),
),
Container(
margin: EdgeInsets.symmetric(horizontal: 20, vertical: 25),
child: TextFormField(
decoration: InputDecoration(hintText: 'CVV'),
maxLength: 3,
onChanged: (value) {
setState(() {
cvv = value;
});
},
focusNode: _focusNode,
),
),
],
)
],
),
),
);
}
}