Skip to content

Commit

Permalink
✨ Dart 3 Support (#146)
Browse files Browse the repository at this point in the history
- Added dart 3 support for the package and the example app.
- Added flutter_lints for code analysis of the package.
- Solved lints warnings.
  • Loading branch information
aditya-css authored Oct 2, 2023
1 parent 0922204 commit 35650cc
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fixed credit card padding in RTL [#139](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/pull/139).
- Fixed [#138](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/issues/138)
AutoValidateMode only applied to Card Number text field.
- Added dart 3 support [#146](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/pull/146).

# [3.0.7](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/tree/3.0.7)

Expand Down
13 changes: 4 additions & 9 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
#
# This file contains the analysis options used by Flutter tools, such as IntelliJ,
# Android Studio, and the `flutter analyze` command.
include: package:flutter_lints/flutter.yaml

analyzer:
strong-mode:
implicit-dynamic: false
errors:
# treat missing required parameters as a warning (not a hint)
missing_required_param: warning
Expand All @@ -32,12 +31,8 @@ analyzer:
# Stream and not importing dart:async
# Please see https://github.com/flutter/flutter/pull/24528 for details.
sdk_version_async_exported_from_core: ignore
exclude:
- 'bin/cache/**'
# the following two are relative to the stocks example and the flutter package respectively
# see https://github.com/dart-lang/sdk/issues/28463
- 'lib/i18n/stock_messages_*.dart'
- 'lib/src/http/**'
language:
strict-raw-types: true

linter:
rules:
Expand Down Expand Up @@ -173,4 +168,4 @@ linter:
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
- valid_regexps
# - void_checks # not yet tested
# - void_checks # not yet tested
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:flutter_credit_card/flutter_credit_card.dart';
void main() => runApp(const MySample());

class MySample extends StatefulWidget {
const MySample({Key? key}) : super(key: key);
const MySample({super.key});

@override
State<StatefulWidget> createState() => MySampleState();
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ publish_to: none
version: 1.0.0+1

environment:
sdk: ">=2.17.0 <3.0.0"
sdk: ">=2.17.0 <4.0.0"

dependencies:
flutter:
Expand Down
1 change: 1 addition & 0 deletions lib/credit_card_animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class AnimationCard extends StatelessWidget {
const AnimationCard({
required this.child,
required this.animation,
super.key,
});

final Widget child;
Expand Down
8 changes: 4 additions & 4 deletions lib/credit_card_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class CreditCardForm extends StatefulWidget {
final bool disableCardNumberAutoFillHints;

@override
_CreditCardFormState createState() => _CreditCardFormState();
State<CreditCardForm> createState() => _CreditCardFormState();
}

class _CreditCardFormState extends State<CreditCardForm> {
Expand Down Expand Up @@ -305,7 +305,7 @@ class _CreditCardFormState extends State<CreditCardForm> {
if (_expiryDateController.text
.startsWith(RegExp('[2-9]'))) {
_expiryDateController.text =
'0' + _expiryDateController.text;
'0${_expiryDateController.text}';
}
setState(() {
expiryDate = _expiryDateController.text;
Expand Down Expand Up @@ -369,9 +369,9 @@ class _CreditCardFormState extends State<CreditCardForm> {
controller: _cvvCodeController,
cursorColor: widget.cursorColor ?? themeColor,
onEditingComplete: () {
if (widget.isHolderNameVisible)
if (widget.isHolderNameVisible) {
FocusScope.of(context).requestFocus(cardHolderNode);
else {
} else {
FocusScope.of(context).unfocus();
onCreditCardModelChange(creditCardModel);
widget.onFormComplete?.call();
Expand Down
26 changes: 10 additions & 16 deletions lib/credit_card_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'floating_animation/floating_event.dart';
import 'flutter_credit_card_platform_interface.dart';
import 'glassmorphism_config.dart';

const Map<CardType, String> CardTypeIconAsset = <CardType, String>{
const Map<CardType, String> cardTypeIconAsset = <CardType, String>{
CardType.visa: 'icons/visa.png',
CardType.rupay: 'icons/rupay.png',
CardType.americanExpress: 'icons/amex.png',
Expand Down Expand Up @@ -181,7 +181,7 @@ class CreditCardWidget extends StatefulWidget {

/// floating animation enabled/disabled
@override
_CreditCardWidgetState createState() => _CreditCardWidgetState();
State<CreditCardWidget> createState() => _CreditCardWidgetState();
}

class _CreditCardWidgetState extends State<CreditCardWidget>
Expand Down Expand Up @@ -441,23 +441,20 @@ class _CreditCardWidgetState extends State<CreditCardWidget>

String number = widget.cardNumber;
if (widget.obscureCardNumber) {
final String stripped = number.replaceAll(RegExp(r'[^\d]'), '');
final String stripped = number.replaceAll(RegExp(r'\D'), '');
if (widget.obscureInitialCardNumber && stripped.length > 4) {
final String start = number
.substring(0, number.length - 5)
.trim()
.replaceAll(RegExp(r'\d'), '*');
number = start + ' ' + stripped.substring(stripped.length - 4);
number = '$start ${stripped.substring(stripped.length - 4)}';
} else if (stripped.length > 8) {
final String middle = number
.substring(4, number.length - 5)
.trim()
.replaceAll(RegExp(r'\d'), '*');
number = stripped.substring(0, 4) +
' ' +
middle +
' ' +
stripped.substring(stripped.length - 4);
number =
'${stripped.substring(0, 4)} $middle ${stripped.substring(stripped.length - 4)}';
}
}

Expand Down Expand Up @@ -889,7 +886,7 @@ class _CreditCardWidgetState extends State<CreditCardWidget>
return customCardTypeIcon.first.cardImage;
} else {
return Image.asset(
CardTypeIconAsset[cardType]!,
cardTypeIconAsset[cardType]!,
height: 48,
width: 48,
package: 'flutter_credit_card',
Expand Down Expand Up @@ -917,7 +914,7 @@ class _CreditCardWidgetState extends State<CreditCardWidget>
case CardType.elo:
case CardType.hipercard:
icon = Image.asset(
CardTypeIconAsset[ccType]!,
cardTypeIconAsset[ccType]!,
height: 48,
width: 48,
package: 'flutter_credit_card',
Expand All @@ -927,7 +924,7 @@ class _CreditCardWidgetState extends State<CreditCardWidget>

case CardType.americanExpress:
icon = Image.asset(
CardTypeIconAsset[ccType]!,
cardTypeIconAsset[ccType]!,
height: 48,
width: 48,
package: 'flutter_credit_card',
Expand All @@ -936,10 +933,7 @@ class _CreditCardWidgetState extends State<CreditCardWidget>
break;

default:
icon = Container(
height: 48,
width: 48,
);
icon = const SizedBox(height: 48, width: 48);
isAmex = false;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.1
flutter_lints: ^2.0.3

flutter:
plugin:
Expand Down

0 comments on commit 35650cc

Please sign in to comment.