|
| 1 | + |
| 2 | +```dart |
| 3 | + CreditCardWidget( |
| 4 | + cardNumber: cardNumber, |
| 5 | + expiryDate: expiryDate, |
| 6 | + cardHolderName: cardHolderName, |
| 7 | + cvvCode: cvvCode, |
| 8 | + showBackView: isCvvFocused, |
| 9 | + onCreditCardWidgetChange: (CreditCardBrand brand) {}, |
| 10 | + bankName: 'Name of the Bank', |
| 11 | + cardBgColor: Colors.black87, |
| 12 | + glassmorphismConfig: Glassmorphism.defaultConfig(), |
| 13 | + enableFloatingCard: true, |
| 14 | + floatingConfig: FloatingConfig( |
| 15 | + isGlareEnabled: true, |
| 16 | + isShadowEnabled: true, |
| 17 | + shadowConfig: FloatingShadowConfig(), |
| 18 | + ), |
| 19 | + backgroundImage: 'assets/card_bg.png', |
| 20 | + backgroundNetworkImage: 'https://www.xyz.com/card_bg.png', |
| 21 | + labelValidThru: 'VALID\nTHRU', |
| 22 | + obscureCardNumber: true, |
| 23 | + obscureInitialCardNumber: false, |
| 24 | + obscureCardCvv: true, |
| 25 | + labelCardHolder: 'CARD HOLDER', |
| 26 | + labelValidThru: 'VALID\nTHRU', |
| 27 | + cardType: CardType.mastercard, |
| 28 | + isHolderNameVisible: false, |
| 29 | + height: 175, |
| 30 | + textStyle: TextStyle(color: Colors.yellowAccent), |
| 31 | + width: MediaQuery.of(context).size.width, |
| 32 | + isChipVisible: true, |
| 33 | + isSwipeGestureEnabled: true, |
| 34 | + animationDuration: Duration(milliseconds: 1000), |
| 35 | + frontCardBorder: Border.all(color: Colors.grey), |
| 36 | + backCardBorder: Border.all(color: Colors.grey), |
| 37 | + chipColor: Colors.red, |
| 38 | + padding: 16, |
| 39 | + customCardTypeIcons: <CustomCardTypeIcons>[ |
| 40 | + CustomCardTypeIcons( |
| 41 | + cardType: CardType.mastercard, |
| 42 | + cardImage: Image.asset( |
| 43 | + 'assets/mastercard.png', |
| 44 | + height: 48, |
| 45 | + width: 48, |
| 46 | + ), |
| 47 | + ), |
| 48 | + ], |
| 49 | + ), |
| 50 | +``` |
| 51 | + |
| 52 | +*Glassmorphism UI* |
| 53 | + |
| 54 | ++ Default configuration |
| 55 | +```dart |
| 56 | + CreditCardWidget( |
| 57 | + glassmorphismConfig: Glassmorphism.defaultConfig(), |
| 58 | + ); |
| 59 | +``` |
| 60 | + |
| 61 | ++ Custom configuration |
| 62 | +```dart |
| 63 | + CreditCardWidget( |
| 64 | + glassmorphismConfig: Glassmorphism( |
| 65 | + blurX: 10.0, |
| 66 | + blurY: 10.0, |
| 67 | + gradient: LinearGradient( |
| 68 | + begin: Alignment.topLeft, |
| 69 | + end: Alignment.bottomRight, |
| 70 | + colors: <Color>[ |
| 71 | + Colors.grey.withAlpha(20), |
| 72 | + Colors.white.withAlpha(20), |
| 73 | + ], |
| 74 | + stops: const <double>[ |
| 75 | + 0.3, |
| 76 | + 0, |
| 77 | + ], |
| 78 | + ), |
| 79 | + ), |
| 80 | + ), |
| 81 | +``` |
| 82 | + |
| 83 | +*Floating Card* |
| 84 | + |
| 85 | ++ Default Configuration |
| 86 | +```dart |
| 87 | + CreditCardWidget( |
| 88 | + enableFloatingCard: true, |
| 89 | + ); |
| 90 | +``` |
| 91 | + |
| 92 | ++ Custom Configuration |
| 93 | +```dart |
| 94 | + CreditCardWidget( |
| 95 | + enableFloatingCard: true, |
| 96 | + floatingConfig: FloatingConfig( |
| 97 | + isGlareEnabled: true, |
| 98 | + isShadowEnabled: true, |
| 99 | + shadowConfig: FloatingShadowConfig( |
| 100 | + offset: Offset(10, 10), |
| 101 | + color: Colors.black84, |
| 102 | + blurRadius: 15, |
| 103 | + ), |
| 104 | + ), |
| 105 | + ); |
| 106 | +``` |
| 107 | +> NOTE: Currently the floating card animation is not supported on mobile platform browsers. |
| 108 | +
|
| 109 | +2. Adding CreditCardForm |
| 110 | + |
| 111 | +```dart |
| 112 | + CreditCardForm( |
| 113 | + formKey: formKey, // Required |
| 114 | + cardNumber: cardNumber, // Required |
| 115 | + expiryDate: expiryDate, // Required |
| 116 | + cardHolderName: cardHolderName, // Required |
| 117 | + cvvCode: cvvCode, // Required |
| 118 | + cardNumberKey: cardNumberKey, |
| 119 | + cvvCodeKey: cvvCodeKey, |
| 120 | + expiryDateKey: expiryDateKey, |
| 121 | + cardHolderKey: cardHolderKey, |
| 122 | + onCreditCardModelChange: (CreditCardModel data) {}, // Required |
| 123 | + obscureCvv: true, |
| 124 | + obscureNumber: true, |
| 125 | + isHolderNameVisible: true, |
| 126 | + isCardNumberVisible: true, |
| 127 | + isExpiryDateVisible: true, |
| 128 | + enableCvv: true, |
| 129 | + cvvValidationMessage: 'Please input a valid CVV', |
| 130 | + dateValidationMessage: 'Please input a valid date', |
| 131 | + numberValidationMessage: 'Please input a valid number', |
| 132 | + cardNumberValidator: (String? cardNumber){}, |
| 133 | + expiryDateValidator: (String? expiryDate){}, |
| 134 | + cvvValidator: (String? cvv){}, |
| 135 | + cardHolderValidator: (String? cardHolderName){}, |
| 136 | + onFormComplete: () { |
| 137 | + // callback to execute at the end of filling card data |
| 138 | + }, |
| 139 | + autovalidateMode: AutovalidateMode.always, |
| 140 | + disableCardNumberAutoFillHints: false, |
| 141 | + inputConfiguration: const InputConfiguration( |
| 142 | + cardNumberDecoration: InputDecoration( |
| 143 | + border: OutlineInputBorder(), |
| 144 | + labelText: 'Number', |
| 145 | + hintText: 'XXXX XXXX XXXX XXXX', |
| 146 | + ), |
| 147 | + expiryDateDecoration: InputDecoration( |
| 148 | + border: OutlineInputBorder(), |
| 149 | + labelText: 'Expired Date', |
| 150 | + hintText: 'XX/XX', |
| 151 | + ), |
| 152 | + cvvCodeDecoration: InputDecoration( |
| 153 | + border: OutlineInputBorder(), |
| 154 | + labelText: 'CVV', |
| 155 | + hintText: 'XXX', |
| 156 | + ), |
| 157 | + cardHolderDecoration: InputDecoration( |
| 158 | + border: OutlineInputBorder(), |
| 159 | + labelText: 'Card Holder', |
| 160 | + ), |
| 161 | + cardNumberTextStyle: TextStyle( |
| 162 | + fontSize: 10, |
| 163 | + color: Colors.black, |
| 164 | + ), |
| 165 | + cardHolderTextStyle: TextStyle( |
| 166 | + fontSize: 10, |
| 167 | + color: Colors.black, |
| 168 | + ), |
| 169 | + expiryDateTextStyle: TextStyle( |
| 170 | + fontSize: 10, |
| 171 | + color: Colors.black, |
| 172 | + ), |
| 173 | + cvvCodeTextStyle: TextStyle( |
| 174 | + fontSize: 10, |
| 175 | + color: Colors.black, |
| 176 | + ), |
| 177 | + ), |
| 178 | + ), |
| 179 | +``` |
0 commit comments