Skip to content

Commit

Permalink
Feat: ✨ Allow disabling cvv code for credit card form
Browse files Browse the repository at this point in the history
  • Loading branch information
ujas-m-simformsolutions committed Mar 3, 2023
1 parent da547ff commit 0d5ebd1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 48 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# [3.0.6](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/tree/3.0.6)

- Add documentation for public apis.
- Fixed [#126](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/issues/126) Added a flag to disable autofill hints for credit card number as workaround to fix incorrect keyboard.
- Fixed [#126](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/issues/126) Add a flag to disable autofill hints for credit card number as workaround to fix incorrect keyboard.
- Enhancement [#129](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/pull/129) Obscure initial character in credit card widget
- Enhancement [#131](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/pull/131) Add a flag to enable/disable cvv in credit card form

# [3.0.5](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/tree/3.0.5)

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ import 'package:flutter_credit_card/flutter_credit_card.dart';
themeColor: Colors.red,
obscureCvv: true,
obscureNumber: true,
isHolderNameVisible: false,
isCardNumberVisible: false,
isExpiryDateVisible: false,
isHolderNameVisible: true,
isCardNumberVisible: true,
isExpiryDateVisible: true,
enableCvv: true,
cardNumberValidator: (String? cardNumber){},
expiryDateValidator: (String? expiryDate){},
cvvValidator: (String? cvv){},
Expand Down
97 changes: 53 additions & 44 deletions lib/credit_card_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CreditCardForm extends StatefulWidget {
this.isHolderNameVisible = true,
this.isCardNumberVisible = true,
this.isExpiryDateVisible = true,
this.enableCvv = true,
this.autovalidateMode,
this.cardNumberValidator,
this.expiryDateValidator,
Expand Down Expand Up @@ -90,14 +91,18 @@ class CreditCardForm extends StatefulWidget {
/// Defaults to false.
final bool obscureNumber;

/// Allows editing the holder name by enabling this in the credit card form.
/// Allow editing the holder name by enabling this in the credit card form.
/// Defaults to true.
final bool isHolderNameVisible;

/// Allows editing the credit card number by enabling this in the credit
/// Allow editing the credit card number by enabling this in the credit
/// card form. Defaults to true.
final bool isCardNumberVisible;

/// Allow editing the cvv code by enabling this in the credit card form.
/// Defaults to true.
final bool enableCvv;

/// Allows editing the expiry date by enabling this in the credit
/// card form. Defaults to true.
final bool isExpiryDateVisible;
Expand Down Expand Up @@ -350,49 +355,53 @@ class _CreditCardFormState extends State<CreditCardForm> {
),
),
Expanded(
child: Container(
padding: const EdgeInsets.symmetric(vertical: 8.0),
margin: const EdgeInsets.only(left: 16, top: 8, right: 16),
child: TextFormField(
key: widget.cvvCodeKey,
obscureText: widget.obscureCvv,
focusNode: cvvFocusNode,
controller: _cvvCodeController,
cursorColor: widget.cursorColor ?? themeColor,
onEditingComplete: () {
if (widget.isHolderNameVisible)
FocusScope.of(context).requestFocus(cardHolderNode);
else {
FocusScope.of(context).unfocus();
onCreditCardModelChange(creditCardModel);
widget.onFormComplete?.call();
}
},
style: TextStyle(
color: widget.textColor,
child: Visibility(
visible: widget.enableCvv,
child: Container(
padding: const EdgeInsets.symmetric(vertical: 8.0),
margin:
const EdgeInsets.only(left: 16, top: 8, right: 16),
child: TextFormField(
key: widget.cvvCodeKey,
obscureText: widget.obscureCvv,
focusNode: cvvFocusNode,
controller: _cvvCodeController,
cursorColor: widget.cursorColor ?? themeColor,
onEditingComplete: () {
if (widget.isHolderNameVisible)
FocusScope.of(context).requestFocus(cardHolderNode);
else {
FocusScope.of(context).unfocus();
onCreditCardModelChange(creditCardModel);
widget.onFormComplete?.call();
}
},
style: TextStyle(
color: widget.textColor,
),
decoration: widget.cvvCodeDecoration,
keyboardType: TextInputType.number,
textInputAction: widget.isHolderNameVisible
? TextInputAction.next
: TextInputAction.done,
autofillHints: const <String>[
AutofillHints.creditCardSecurityCode
],
onChanged: (String text) {
setState(() {
cvvCode = text;
creditCardModel.cvvCode = cvvCode;
onCreditCardModelChange(creditCardModel);
});
},
validator: widget.cvvValidator ??
(String? value) {
if (value!.isEmpty || value.length < 3) {
return widget.cvvValidationMessage;
}
return null;
},
),
decoration: widget.cvvCodeDecoration,
keyboardType: TextInputType.number,
textInputAction: widget.isHolderNameVisible
? TextInputAction.next
: TextInputAction.done,
autofillHints: const <String>[
AutofillHints.creditCardSecurityCode
],
onChanged: (String text) {
setState(() {
cvvCode = text;
creditCardModel.cvvCode = cvvCode;
onCreditCardModelChange(creditCardModel);
});
},
validator: widget.cvvValidator ??
(String? value) {
if (value!.isEmpty || value.length < 3) {
return widget.cvvValidationMessage;
}
return null;
},
),
),
),
Expand Down

0 comments on commit 0d5ebd1

Please sign in to comment.