Skip to content

Commit

Permalink
Merge pull request #66 from ocakliemre/expired-date-validation-bug-fix
Browse files Browse the repository at this point in the history
The cards expired date validation control bug fixed.
  • Loading branch information
shwetachauhan-simform committed Sep 12, 2022
2 parents cbee456 + 52c1cf3 commit 02b1b18
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
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

0 comments on commit 02b1b18

Please sign in to comment.