Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: ✨ Allow disabling cvv code for credit card form #131

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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