@@ -7,7 +7,7 @@ import 'package:u_credit_card/src/ui/credit_card_top_section_view.dart';
7
7
import 'package:u_credit_card/src/ui/credit_card_validity_view.dart' ;
8
8
import 'package:u_credit_card/src/utils/credit_card_helper.dart' ;
9
9
10
- /// Types of Cards
10
+ /// Types of Cards.
11
11
enum CardType {
12
12
/// Credit Card
13
13
credit,
@@ -25,22 +25,40 @@ enum CardType {
25
25
other,
26
26
}
27
27
28
- /// Position of the Card Provider logo
29
- /// Left or Right in the top part of the card
28
+ /// Types of payment network.
29
+ enum CreditCardType {
30
+ /// VISA
31
+ visa,
32
+
33
+ /// Mastercard
34
+ mastercard,
35
+
36
+ /// AMEX
37
+ amex,
38
+
39
+ /// Discover
40
+ discover,
41
+
42
+ /// None
43
+ none,
44
+ }
45
+
46
+ /// Position of the Card Provider logo.
47
+ /// Left or Right in the top part of the card.
30
48
enum CardProviderLogoPosition {
31
- /// Set the logo to the left side
49
+ /// Set the logo to the left side.
32
50
left,
33
51
34
- /// Set the logo to the left side
52
+ /// Set the logo to the left side.
35
53
right;
36
54
37
- /// Find if the logo is set to left or not
55
+ /// Find if the logo is set to left or not.
38
56
bool get isLeft => this == CardProviderLogoPosition .left;
39
57
}
40
58
41
- /// Creates Credit Card UI
59
+ /// Creates Credit Card UI.
42
60
class CreditCardUi extends StatelessWidget {
43
- /// Creates Credit Card UI
61
+ /// Creates Credit Card UI.
44
62
const CreditCardUi ({
45
63
super .key,
46
64
required this .cardHolderFullName,
@@ -53,44 +71,46 @@ class CreditCardUi extends StatelessWidget {
53
71
this .scale = 1.0 ,
54
72
this .placeNfcIconAtTheEnd = false ,
55
73
this .cardType = CardType .credit,
74
+ this .creditCardType,
56
75
this .cardProviderLogo,
57
76
this .cardProviderLogoPosition = CardProviderLogoPosition .right,
58
77
this .backgroundDecorationImage,
78
+ @Deprecated ('Use `creditCardType: CreditCardType.none` instead' )
59
79
this .disableShowingCardLogo = false ,
60
80
});
61
81
62
- /// Full Name of the Card Holder
82
+ /// Full Name of the Card Holder.
63
83
final String cardHolderFullName;
64
84
65
- /// Full credit card number, can support asterisks
85
+ /// Full credit card number, can support asterisks.
66
86
final String cardNumber;
67
87
68
88
/// Enter valid from date of the card month and year like mm/yy,
69
89
///
70
- /// Example 01/23, here 01 means month January & 23 means year 2023
71
- /// Optional field, can be skipped
90
+ /// Example 01/23, here 01 means month January & 23 means year 2023.
91
+ /// Optional field, can be skipped.
72
92
final String ? validFrom;
73
93
74
- /// Enter validity of the card month and year like mm/yy,
94
+ /// Enter validity of the card month and year like mm/yy.
75
95
///
76
- /// Example 01/28, here 01 means month January & 28 means year 2028
96
+ /// Example 01/28, here 01 means month January & 28 means year 2028.
77
97
final String validThru;
78
98
79
99
/// Top Left Color for the Gradient,
80
- /// by default it's `Colors.purple`
100
+ /// by default it's `Colors.purple` .
81
101
///
82
- /// Tip: Avoid light colors, because texts are now white
102
+ /// Tip: Avoid light colors, because texts are now white.
83
103
final Color topLeftColor;
84
104
85
105
/// Bottom Left Color for the Gradient,
86
- /// by default it's deeper version of `topLeftColor`
106
+ /// by default it's deeper version of `topLeftColor` .
87
107
///
88
- /// Tip: Avoid light colors, because texts are now white
108
+ /// Tip: Avoid light colors, because texts are now white.
89
109
final Color ? bottomRightColor;
90
110
91
111
/// Shows a NFC icon to tell user if the card supports NFC feature.
92
112
///
93
- /// By default it is `true`
113
+ /// By default it is `true` .
94
114
final bool doesSupportNfc;
95
115
96
116
/// Places NFC icon at the opposite side of the chip,
@@ -101,39 +121,47 @@ class CreditCardUi extends StatelessWidget {
101
121
/// so, icon will be beside the chip if nfc is enabled.
102
122
final bool placeNfcIconAtTheEnd;
103
123
104
- /// Can scale the credit card
124
+ /// Can scale the credit card.
105
125
///
106
126
/// if you want reduce the size,
107
- /// set the value less than 1, else set greater than 1
127
+ /// set the value less than 1, else set greater than 1.
108
128
///
109
- /// By default the value is 1.0
129
+ /// By default the value is 1.0.
110
130
final double scale;
111
131
112
- /// Provide the type of the card.
132
+ /// Provide the type of the card - credit or debit .
113
133
/// By default, it's `CardType.credit`
114
134
///
115
- /// Set `CardType.other` if you don't want to set anything
135
+ /// Set `CardType.other` if you don't want to set anything.
116
136
final CardType cardType;
117
137
138
+ /// Set Credit card type to set network provider logo - VISA, Mastercard, etc.
139
+ ///
140
+ /// Set `creditCardType: CreditCardType.none` to disable showing the logo.
141
+ /// If this value is skipped, the card will show the logo automatically
142
+ /// based on the `cardNumber` .
143
+ final CreditCardType ? creditCardType;
144
+
118
145
/// Provide the logo of the card provider (Optional).
119
146
final Widget ? cardProviderLogo;
120
147
121
148
/// Set the position of the card provider,
122
- /// by default, it is on the right
149
+ /// by default, it is on the right.
123
150
///
124
- /// Set `CardProviderLogoPosition.left` or `CardProviderLogoPosition.right`
151
+ /// Set `CardProviderLogoPosition.left` or `CardProviderLogoPosition.right` .
125
152
final CardProviderLogoPosition cardProviderLogoPosition;
126
153
127
- /// Set Background image, can support both asset and network image
154
+ /// Set Background image, can support both asset and network image.
128
155
final DecorationImage ? backgroundDecorationImage;
129
156
130
- /// Disable card type logo, just set to `true`
157
+ /// Disable credit card type logo, just set to `true` .
158
+ @Deprecated ('Use `creditCardType: CreditCardType.none` instead' )
131
159
final bool disableShowingCardLogo;
132
160
133
161
@override
134
162
Widget build (BuildContext context) {
135
163
final cardNumberMasked = CreditCardHelper .maskCreditCardNumber (
136
- cardNumber.replaceAll (' ' , '' ),
164
+ cardNumber.replaceAll (' ' , '' ). replaceAll ( '-' , '' ) ,
137
165
);
138
166
139
167
final validFromMasked = validFrom == null
@@ -152,12 +180,24 @@ class CreditCardUi extends StatelessWidget {
152
180
);
153
181
154
182
Widget cardLogoWidget;
155
- final cardLogoString = CreditCardHelper .getCardLogo (cardNumberMasked);
156
- if (disableShowingCardLogo || cardLogoString.isEmpty) {
183
+ final cardLogoString = CreditCardHelper .getCardLogoFromCardNumber (
184
+ cardNumber: cardNumberMasked,
185
+ );
186
+
187
+ if (disableShowingCardLogo ||
188
+ cardLogoString.isEmpty ||
189
+ creditCardType == CreditCardType .none) {
157
190
cardLogoWidget = const SizedBox .shrink ();
191
+ } else if (creditCardType != null ) {
192
+ cardLogoWidget = Image .asset (
193
+ CreditCardHelper .getCardLogoFromType (creditCardType: creditCardType! ),
194
+ package: UiConstants .packageName,
195
+ );
158
196
} else {
159
197
cardLogoWidget = Image .asset (
160
- CreditCardHelper .getCardLogo (cardNumberMasked),
198
+ CreditCardHelper .getCardLogoFromCardNumber (
199
+ cardNumber: cardNumberMasked,
200
+ ),
161
201
package: UiConstants .packageName,
162
202
);
163
203
}
@@ -238,7 +278,9 @@ class CreditCardUi extends StatelessWidget {
238
278
top: 108 ,
239
279
left: 20 ,
240
280
child: CreditCardText (
241
- cardNumberMasked,
281
+ cardNumberMasked.length > 20
282
+ ? cardNumberMasked.substring (0 , 20 )
283
+ : cardNumberMasked,
242
284
),
243
285
),
244
286
],
0 commit comments