Credit Card
Loading preview
Starting the Flutter app
A showcase of Flutter's credit card display functionality
import 'package:flutter/material.dart';
class CreditCard extends StatelessWidget {
const CreditCard({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Credit Card')),
body: Padding(
padding: const EdgeInsets.all(16),
child: Card(
elevation: 8,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
child: AspectRatio(
aspectRatio: 1.586,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Colors.deepPurple.shade700,
Colors.deepPurple.shade900,
],
),
borderRadius: BorderRadius.circular(20),
),
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Icon(Icons.credit_card, color: Colors.white.withValues(alpha: 0.9), size: 32),
Text('VISA', style: TextStyle(
color: Colors.white.withValues(alpha: 0.9),
fontSize: 24,
fontWeight: FontWeight.bold,
)),
],
),
Text('**** **** **** 4242',
style: TextStyle(
color: Colors.white.withValues(alpha: 0.9),
fontSize: 20,
letterSpacing: 4)),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('CARD HOLDER',
style: TextStyle(
color: Colors.white.withValues(alpha: 0.6),
fontSize: 10)),
Text('John Doe',
style: TextStyle(
color: Colors.white.withValues(alpha: 0.9),
fontSize: 16)),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('EXPIRES',
style: TextStyle(
color: Colors.white.withValues(alpha: 0.6),
fontSize: 10)),
Text('12/28',
style: TextStyle(
color: Colors.white.withValues(alpha: 0.9),
fontSize: 16)),
],
),
],
),
],
),
),
),
),
),
);
}
}
Add it to your project
Copies the Dart source into your app, so you own it. Flutter SDK only, no extra packages.
First time? Run dart pub global activate fluttertemplates_dev, or read the CLI guide.
How it works
Purely presentational: one Card holding a purple LinearGradient, sized by AspectRatio at 1.586, the proportions of a physical bank card. MainAxisAlignment.spaceBetween spreads three rows across it, namely brand, masked number, and holder with expiry. There is no state, no gesture and no flip side for a CVV, and every value, including VISA, is hardcoded.
Adapting it
- Add constructor fields to
CreditCardfor last four digits, holder, expiry and brand. - Keep the
**** **** **** 4242masked format and pass only the last four digits in, never a full card number. - Make the
colorslist a parameter so each brand or account can have its own gradient.