From 0d5ebd1c85b9ea9b3379d997a87726761d774925 Mon Sep 17 00:00:00 2001 From: ujas-m-simformsolutions Date: Fri, 3 Mar 2023 11:18:11 +0530 Subject: [PATCH] Feat: :sparkles: Allow disabling cvv code for credit card form --- CHANGELOG.md | 3 +- README.md | 7 +-- lib/credit_card_form.dart | 97 +++++++++++++++++++++------------------ 3 files changed, 59 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d84fe0..fd71759 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index dc20514..41c7e78 100644 --- a/README.md +++ b/README.md @@ -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){}, diff --git a/lib/credit_card_form.dart b/lib/credit_card_form.dart index c303046..f2da606 100644 --- a/lib/credit_card_form.dart +++ b/lib/credit_card_form.dart @@ -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, @@ -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; @@ -350,49 +355,53 @@ class _CreditCardFormState extends State { ), ), 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 [ + 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 [ - 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; - }, ), ), ),