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

Input decorators, obscure number and CVV, validations #22

Merged
merged 21 commits into from
Jan 1, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.4
* Feature : Added number and CVV obfuscation
* Feature : Added input decorations
* Feature : Added simple card input validations

## 0.1.3
* Feature : Applied Default ThemeData.

Expand Down
62 changes: 26 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,57 +46,47 @@ import 'package:flutter_credit_card/flutter_credit_card.dart';
cvvCode: cvvCode,
showBackView: isCvvFocused,
cardbgColor: Colors.black,
obscureCardNumber: true,
obscureCardCvv: true,
height: 175,
textStyle: TextStyle(color: Colors.yellowAccent),
width: MediaQuery.of(context).size.width,
animationDuration: Duration(milliseconds: 1000),
),
),
```
3. Adding CreditCardForm

```dart
CreditCardForm(
formKey: formKey, // Required
onCreditCardModelChange: (CreditCardModel data) {}, // Required
themeColor: Colors.red,
onCreditCardModelChange: (CreditCardModel data) {},
obscureCvv: true,
obscureNumber: true,
cardNumberDecoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Number',
hintText: 'XXXX XXXX XXXX XXXX',
),
expiryDateDecoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Expired Date',
hintText: 'XX/XX',
),
cvvCodeDecoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'CVV',
hintText: 'XXX',
),
cardHolderDecoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Card Holder',
),
),
```

## Localization

To localize text field hints and labels, use `LocalizedText` model.

```dart
const LocalizedText localizedText = LocalizedText(
cardNumberLabel: 'Kreditkartennummer',
cardNumberHint: 'XXXX-XXXX-XXXX-XXXX',
expiryDateLabel: 'Ablaufdatum',
expiryDateHint: 'MM/JJ',
cvvLabel: 'Kartenprüfnummer',
cvvHint: 'XXX',
cardHolderLabel: 'Karteninhaber',
cardHolderHint: 'Max Mustermann',
);

return Column(
children: <Widget>[
CreditCardWidget(
cardNumber: cardNumber,
expiryDate: expiryDate,
cardHolderName: cardHolderName,
cvvCode: cvvCode,
showBackView: isCvvFocused,
localizedText: localizedText,
),
Expanded(
child: SingleChildScrollView(
child: CreditCardForm(
onCreditCardModelChange: onCreditCardModelChange,
localizedText: localizedText,
),
),
],
);
```

## How to use
Check out the **example** app in the [example](example) directory or the 'Example' tab on pub.dartlang.org for a more complete example.
Expand Down
1 change: 1 addition & 0 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
11 changes: 11 additions & 0 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\src\flutter"
export "FLUTTER_APPLICATION_PATH=C:\Users\Deana\Flutter\flutter_libraries\flutter_credit_card\example"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=C:\src\flutter\bin\cache\artifacts\engine\ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
60 changes: 57 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class MySampleState extends State<MySample> {
String cardHolderName = '';
String cvvCode = '';
bool isCvvFocused = false;
final GlobalKey<FormState> formKey = GlobalKey<FormState>();

@override
Widget build(BuildContext context) {
Expand All @@ -38,14 +39,67 @@ class MySampleState extends State<MySample> {
cardHolderName: cardHolderName,
cvvCode: cvvCode,
showBackView: isCvvFocused,
obscureCardNumber: true,
obscureCardCvv: true,
),
Expanded(
child: SingleChildScrollView(
child: CreditCardForm(
onCreditCardModelChange: onCreditCardModelChange,
child: Column(
children: [
CreditCardForm(
formKey: formKey,
obscureCvv: true,
obscureNumber: true,
cardNumberDecoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Number',
hintText: 'XXXX XXXX XXXX XXXX',
),
expiryDateDecoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Expired Date',
hintText: 'XX/XX',
),
cvvCodeDecoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'CVV',
hintText: 'XXX',
),
cardHolderDecoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Card Holder',
),
onCreditCardModelChange: onCreditCardModelChange,
),
RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
child: Container(
margin: const EdgeInsets.all(8),
child: const Text(
'Validate',
style: TextStyle(
color: Colors.white,
fontFamily: 'halter',
fontSize: 14,
package: 'flutter_credit_card',
),
),
),
color: const Color(0xff1b447b),
onPressed: () {
if (formKey.currentState.validate()) {
print('valid!');
} else {
print('invalid!');
}
},
)
],
),
),
)
),
],
),
),
Expand Down
74 changes: 58 additions & 16 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,34 +1,62 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
version: "2.4.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "2.0.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
version: "1.1.3"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.11"
version: "1.14.12"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -47,47 +75,54 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.1"
version: "0.1.4"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.12"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.5"
version: "0.12.6"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.1.8"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.2"
pedantic:
version: "1.6.4"
petitparser:
dependency: transitive
description:
name: pedantic
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "2.4.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.1.3"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -99,7 +134,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.5"
version: "1.7.0"
stack_trace:
dependency: transitive
description:
Expand All @@ -120,7 +155,7 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "1.0.5"
term_glyph:
dependency: transitive
description:
Expand All @@ -134,7 +169,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.5"
version: "0.2.15"
typed_data:
dependency: transitive
description:
Expand All @@ -149,5 +184,12 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.6.1"
sdks:
dart: ">=2.2.2 <3.0.0"
dart: ">=2.6.0 <3.0.0"