A Flutter package allows you to easily implement the Credit card's UI easily with the Card detection.
-
Add dependency to
pubspec.yaml
Get the latest version in the 'Installing' tab on pub.dev
dependencies:
flutter_credit_card: <latest_version>
- Import the package
import 'package:flutter_credit_card/flutter_credit_card.dart';
- Adding CreditCardWidget
With required parameters
CreditCardWidget(
cardNumber: cardNumber,
expiryDate: expiryDate,
cardHolderName: cardHolderName,
cvvCode: cvvCode,
showBackView: isCvvFocused, //true when you want to show cvv(back) view
),
With optional parameters
CreditCardWidget(
cardNumber: cardNumber,
expiryDate: expiryDate,
cardHolderName: cardHolderName,
cvvCode: cvvCode,
showBackView: isCvvFocused,
cardbgColor: Colors.black,
glassmorphismConfig: Glassmorphism.defaultConfig(),
enableFloatingCard: true,
floatConfig: FloatConfig(
isGlareEnabled: true,
isShadowEnabled: true,
shadowConfig: FloatShadowConfig.preset(),
),
backgroundImage: 'assets/card_bg.png',
labelValidThru: 'VALID\nTHRU',
obscureCardNumber: true,
obscureInitialCardNumber: false,
obscureCardCvv: true,
isHolderNameVisible: false,
height: 175,
textStyle: TextStyle(color: Colors.yellowAccent),
width: MediaQuery.of(context).size.width,
isChipVisible: true,
isSwipeGestureEnabled: true,
animationDuration: Duration(milliseconds: 1000),
frontCardBorder: Border.all(color: Colors.grey),
backCardBorder: Border.all(color: Colors.grey),
customCardIcons: <CustomCardTypeImage>[
CustomCardTypeImage(
cardType: CardType.mastercard,
cardImage: Image.asset(
'assets/mastercard.png',
height: 48,
width: 48,
),
),
],
),
Glassmorphism UI
- Default configuration
CreditCardWidget(
glassmorphismConfig: Glassmorphism.defaultConfig(),
);
- Custom configuration
CreditCardWidget(
glassmorphismConfig: Glassmorphism(
blurX: 10.0,
blurY: 10.0,
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: <Color>[
Colors.grey.withAlpha(20),
Colors.white.withAlpha(20),
],
stops: const <double>[
0.3,
0,
],
),
),
),
Floating Card
NOTE: Currently the floating card animation is not supported on mobile platform browsers.
Enable floating card animation by passing true
to enableFloatingCard
parameter (default).
You can pass FloatConfig
to the floatConfig
parameter to configure various things like
whether to enable or disable the glare or the shadow associated with the floating animation.
The FloatConfig
also supports shadowConfig
that takes FloatShadowConfig
to configure the
shadow that appears beneath the card when floating animation is turned on.
Passing no value to shadowConfig
would use FloatShadowConfig.preset()
, and floatConfig
would use FloatConfig.preset()
as default configuration.
- Default Shadow Configuration
CreditCardWidget(
enableFloatingCard: true,
floatConfig: FloatConfig(
isGlareEnabled: true,
isShadowEnabled: true,
shadowConfig: FloatShadowConfig.preset(),
),
);
- Custom Shadow Configuration
CreditCardWidget(
enableFloatingCard: true,
floatConfig: FloatConfig(
isGlareEnabled: true,
isShadowEnabled: true,
shadowConfig: FloatShadowConfig(
offset: Offset(10, 10),
color: Colors.black84,
blurRadius: 15,
),
),
);
- Adding CreditCardForm
CreditCardForm(
formKey: formKey, // Required
cardNumberKey: cardNumberKey,
cvvCodeKey: cvvCodeKey,
expiryDateKey: expiryDateKey,
cardHolderKey: cardHolderKey,
onCreditCardModelChange: (CreditCardModel data) {}, // Required
themeColor: Colors.red,
obscureCvv: true,
obscureNumber: true,
isHolderNameVisible: true,
isCardNumberVisible: true,
isExpiryDateVisible: true,
enableCvv: true,
cardNumberValidator: (String? cardNumber){},
expiryDateValidator: (String? expiryDate){},
cvvValidator: (String? cvv){},
cardHolderValidator: (String? cardHolderName){},
onFormComplete: () {
// callback to execute at the end of filling card data
},
cardNumberDecoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Number',
hintText: 'XXXX XXXX XXXX XXXX',
),
expiryDateDecoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Expired Date',
hintText: 'XX/XX',
),
cvvCodeDecoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'CVV',
hintText: 'XXX',
),
cardHolderDecoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Card Holder',
),
),
Check out the example app in the example directory or the 'Example' tab on pub.dartlang.org for a more complete example.
- This package's flip animation is inspired from this Dribbble art.
- This package's float animation is inspired from the Motion flutter package.
Vatsal Tanna |
Devarsh Ranpara |
Kashifa Laliwala |
Sanket Kachchela |
Meet Janani |
Shweta Chauhan |
Kavan Trivedi |
Ujas Majithiya |
- Check out our other available awesome mobile libraries
We have updated license of flutter_credit_card from BSD 2-Clause "Simplified" to MIT.
MIT License
Copyright (c) 2021 Simform Solutions
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.