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

The cards expired date validation control bug fixed. #66

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
2 changes: 1 addition & 1 deletion example/lib/main.dart
Expand Up @@ -191,7 +191,7 @@ class MySampleState extends State<MySample> {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
primary: const Color(0xff1b447b),
backgroundColor: const Color(0xff1b447b),
),
child: Container(
margin: const EdgeInsets.all(12),
Expand Down
10 changes: 6 additions & 4 deletions lib/credit_card_form.dart
@@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_credit_card/flutter_credit_card.dart';

import 'flutter_credit_card.dart';

class CreditCardForm extends StatefulWidget {
const CreditCardForm({
Key? key,
Expand Down Expand Up @@ -113,7 +111,7 @@ class _CreditCardFormState extends State<CreditCardForm> {
super.initState();

createCreditCardModel();

_cardNumberController.text = widget.cardNumber;
_expiryDateController.text = widget.expiryDate;
_cardHolderNameController.text = widget.cardHolderName;
Expand Down Expand Up @@ -247,7 +245,11 @@ class _CreditCardFormState extends State<CreditCardForm> {
final List<String> date = value.split(RegExp(r'/'));
final int month = int.parse(date.first);
final int year = int.parse('20${date.last}');
final DateTime cardDate = DateTime(year, month);
final int lastDayOfMonth = month < 12
? DateTime(year, month + 1, 0).day
: DateTime(year + 1, 1, 0).day;
final DateTime cardDate = DateTime(
year, month, lastDayOfMonth, 23, 59, 59, 999);

if (cardDate.isBefore(now) ||
month > 12 ||
Expand Down