Skip to content

Commit

Permalink
added more options (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
necessarylion authored Apr 16, 2023
1 parent 6a9f986 commit 0ff11d5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.6

* Added support to hide card holder name input

## 0.0.5

* Added support for controller to set input value initially
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ CreditCardForm(
| `onChanged` required | listen for input values changed |
| `cardNumberLabel` | label for card number input |
| `cardHolderLabel` | label for card holder name input |
| `hideCardHolder` | default (false) |
| `expiredDateLabel` | label for expired date input |
| `cvcLabel` | label for security code |
| `cvcLength` | length for security code. default (4) |
| `cvcIcon` | Icon widget for security code. |
| `fontSize` | font size for all inputs and labels. default (16) |
| `controller` | `CreditCardController()` to set initial value to inputs |

Expand Down
72 changes: 39 additions & 33 deletions lib/component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ part of credit_card_form;
class CreditCardForm extends StatefulWidget {
final String? cardNumberLabel;
final String? cardHolderLabel;
final bool? hideCardHolder;
final String? expiredDateLabel;
final String? cvcLabel;
final Widget? cvcIcon;
final int? cvcLength;
final double fontSize;
final CreditCardTheme? theme;
final Function(CreditCardResult) onChanged;
final int? cvcLength;
final CreditCardController? controller;
const CreditCardForm({
super.key,
this.theme,
required this.onChanged,
this.cardNumberLabel,
this.cardHolderLabel,
this.hideCardHolder = false,
this.expiredDateLabel,
this.cvcLabel,
this.fontSize = 16,
this.cvcIcon,
this.cvcLength = 4,
this.fontSize = 16,
this.controller,
});

Expand Down Expand Up @@ -51,6 +55,18 @@ class _CreditCardFormState extends State<CreditCardForm> {

CardType? cardType;

@override
void dispose() {
controllers.forEach((key, value) => value.dispose());
super.dispose();
}

@override
void initState() {
handleController();
super.initState();
}

@override
Widget build(BuildContext context) {
CreditCardTheme theme = widget.theme ?? CreditCardLightTheme();
Expand Down Expand Up @@ -98,20 +114,21 @@ class _CreditCardFormState extends State<CreditCardForm> {
),
),
),
TextInputWidget(
theme: theme,
fontSize: widget.fontSize,
label: widget.cardHolderLabel ?? 'Card holder name',
controller: controllers['card_holder_name'],
bottom: 1,
onChanged: (val) {
setState(() {
params['card_holder_name'] = val;
});
emitResult();
},
keyboardType: TextInputType.name,
),
if (widget.hideCardHolder == false)
TextInputWidget(
theme: theme,
fontSize: widget.fontSize,
label: widget.cardHolderLabel ?? 'Card holder name',
controller: controllers['card_holder_name'],
bottom: 1,
onChanged: (val) {
setState(() {
params['card_holder_name'] = val;
});
emitResult();
},
keyboardType: TextInputType.name,
),
Row(
children: [
Expanded(
Expand Down Expand Up @@ -152,11 +169,12 @@ class _CreditCardFormState extends State<CreditCardForm> {
],
suffixIcon: Padding(
padding: const EdgeInsets.all(8),
child: Image.asset(
'images/cvc.png',
package: 'credit_card_form',
height: 25,
),
child: widget.cvcIcon ??
Image.asset(
'images/cvc.png',
package: 'credit_card_form',
height: 25,
),
),
),
)
Expand All @@ -167,12 +185,6 @@ class _CreditCardFormState extends State<CreditCardForm> {
);
}

@override
void dispose() {
controllers.forEach((key, value) => value.dispose());
super.dispose();
}

emitResult() {
List res = params['expired_date'].split('/');
CreditCardResult result = CreditCardResult(
Expand Down Expand Up @@ -223,10 +235,4 @@ class _CreditCardFormState extends State<CreditCardForm> {
});
}
}

@override
void initState() {
handleController();
super.initState();
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: credit_card_form
description: Flutter Credit/Debit Card Form.
version: 0.0.5
version: 0.0.6
homepage: https://github.com/necessarylion/flutter-credit-card-form

environment:
Expand Down

0 comments on commit 0ff11d5

Please sign in to comment.