From 9d8195e812ffd96fec4cb51707adf526991bd3f0 Mon Sep 17 00:00:00 2001 From: emreocakli Date: Sun, 3 Oct 2021 18:56:31 +0300 Subject: [PATCH 1/2] The cards expired date validation control bux fixed. The expiry date on the cards should be based on the last day of that month. Since the current structure is based only on the month, it does not work correctly. As a bug fix, the last day of the month was found and added to the card expiry date. --- lib/credit_card_form.dart | 4 +++- pubspec.lock | 20 +++++++++++++++++--- pubspec.yaml | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/credit_card_form.dart b/lib/credit_card_form.dart index 1ea5f28..a57447a 100644 --- a/lib/credit_card_form.dart +++ b/lib/credit_card_form.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_credit_card/flutter_credit_card.dart'; +import 'package:jiffy/jiffy.dart'; import 'credit_card_model.dart'; import 'flutter_credit_card.dart'; @@ -239,7 +240,8 @@ class _CreditCardFormState extends State { final List 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 = DateTime(year, Jiffy( DateTime(year,month)).add(months: 1).month, 0 ).day; + final DateTime cardDate = DateTime(year, month, lastDayofMonth); if (cardDate.isBefore(now) || month > 12 || diff --git a/pubspec.lock b/pubspec.lock index 49a0ce6..290a5eb 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.6.1" boolean_selector: dependency: transitive description: @@ -60,6 +60,20 @@ packages: description: flutter source: sdk version: "0.0.0" + intl: + dependency: transitive + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.17.0" + jiffy: + dependency: "direct main" + description: + name: jiffy + url: "https://pub.dartlang.org" + source: hosted + version: "4.1.0" matcher: dependency: transitive description: @@ -92,7 +106,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -127,7 +141,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.3.0" typed_data: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 3430547..108cb1d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,6 +10,7 @@ environment: dependencies: flutter: sdk: flutter + jiffy: ^4.1.0 dev_dependencies: flutter_test: From 52c1cf3fb75fa496eb8cacbaae6e06f65c45081b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20Ocakl=C4=B1?= Date: Thu, 8 Sep 2022 09:34:51 +0300 Subject: [PATCH 2/2] Additional package dependencies removed. --- example/lib/main.dart | 2 +- lib/credit_card_form.dart | 12 +-- pubspec.lock | 160 -------------------------------------- pubspec.yaml | 1 - 4 files changed, 7 insertions(+), 168 deletions(-) delete mode 100644 pubspec.lock diff --git a/example/lib/main.dart b/example/lib/main.dart index 4e4d618..81a613d 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -191,7 +191,7 @@ class MySampleState extends State { shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(8.0), ), - primary: const Color(0xff1b447b), + backgroundColor: const Color(0xff1b447b), ), child: Container( margin: const EdgeInsets.all(12), diff --git a/lib/credit_card_form.dart b/lib/credit_card_form.dart index e8f5d06..ee4a9d0 100644 --- a/lib/credit_card_form.dart +++ b/lib/credit_card_form.dart @@ -1,8 +1,5 @@ import 'package:flutter/material.dart'; import 'package:flutter_credit_card/flutter_credit_card.dart'; -import 'package:jiffy/jiffy.dart'; - -import 'flutter_credit_card.dart'; class CreditCardForm extends StatefulWidget { const CreditCardForm({ @@ -114,7 +111,7 @@ class _CreditCardFormState extends State { super.initState(); createCreditCardModel(); - + _cardNumberController.text = widget.cardNumber; _expiryDateController.text = widget.expiryDate; _cardHolderNameController.text = widget.cardHolderName; @@ -248,8 +245,11 @@ class _CreditCardFormState extends State { final List date = value.split(RegExp(r'/')); final int month = int.parse(date.first); final int year = int.parse('20${date.last}'); - final int lastDayofMonth = DateTime(year, Jiffy( DateTime(year,month)).add(months: 1).month, 0 ).day; - final DateTime cardDate = DateTime(year, month, lastDayofMonth); + 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 || diff --git a/pubspec.lock b/pubspec.lock deleted file mode 100644 index 290a5eb..0000000 --- a/pubspec.lock +++ /dev/null @@ -1,160 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - async: - dependency: transitive - description: - name: async - url: "https://pub.dartlang.org" - source: hosted - version: "2.6.1" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" - characters: - dependency: transitive - description: - name: characters - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - clock: - dependency: transitive - description: - name: clock - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" - collection: - dependency: transitive - description: - name: collection - url: "https://pub.dartlang.org" - source: hosted - version: "1.15.0" - fake_async: - dependency: transitive - description: - name: fake_async - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - intl: - dependency: transitive - description: - name: intl - url: "https://pub.dartlang.org" - source: hosted - version: "0.17.0" - jiffy: - dependency: "direct main" - description: - name: jiffy - url: "https://pub.dartlang.org" - source: hosted - version: "4.1.0" - matcher: - dependency: transitive - description: - name: matcher - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.10" - meta: - dependency: transitive - description: - name: meta - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" - path: - dependency: transitive - description: - name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.1" - stack_trace: - dependency: transitive - description: - name: stack_trace - url: "https://pub.dartlang.org" - source: hosted - version: "1.10.0" - stream_channel: - dependency: transitive - description: - name: stream_channel - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" - string_scanner: - dependency: transitive - description: - name: string_scanner - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" - term_glyph: - dependency: transitive - description: - name: term_glyph - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - test_api: - dependency: transitive - description: - name: test_api - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.0" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" - vector_math: - dependency: transitive - description: - name: vector_math - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" -sdks: - dart: ">=2.12.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 75c4b2f..df8cc6b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,7 +10,6 @@ environment: dependencies: flutter: sdk: flutter - jiffy: ^4.1.0 dev_dependencies: flutter_test: