Skip to content

Commit

Permalink
Fixed warnings in the code & Fixes #82 Added support to add network i…
Browse files Browse the repository at this point in the history
…mage as card background (#85)

* Fixed warnings in the code.

* Fixes #82 Added support to add network image as card background
  • Loading branch information
DhavalRKansara committed Jul 25, 2022
1 parent 807cd33 commit 65094b5
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 3.0.2 - Jul 25, 2022

- Fixed [#73](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/issues/73) - Pass AutovalidateMode to CreditCardForm
- Fixed [#82](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/issues/82) - Added support to add network image as card background
- Fixed [#46](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/issues/46) - Card number Regex issue for safari and web

## 3.0.1 - Oct 12, 2021

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import 'package:flutter_credit_card/flutter_credit_card.dart';
cardBgColor: Colors.black,
glassmorphismConfig: Glassmorphism.defaultConfig(),
backgroundImage: 'assets/card_bg.png',
backgroundNetworkImage: 'image-url'
obscureCardNumber: true,
obscureCardCvv: true,
isHolderNameVisible: false,
Expand Down
3 changes: 0 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ linter:
- always_require_non_null_named_parameters
- always_specify_types
- annotate_overrides
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
- avoid_as
# - avoid_bool_literals_in_conditional_expressions # not yet tested
# - avoid_catches_without_on_clauses # we do this commonly
# - avoid_catching_errors # we do this commonly
Expand Down Expand Up @@ -149,7 +147,6 @@ linter:
- recursive_getters
- slash_for_doc_comments
- sort_constructors_first
- sort_pub_dependencies
- sort_unnamed_constructors_first
# - super_goes_last # no longer needed w/ Dart 2
- test_types_in_equals
Expand Down
2 changes: 0 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_credit_card/credit_card_brand.dart';
import 'package:flutter_credit_card/credit_card_form.dart';
import 'package:flutter_credit_card/credit_card_model.dart';
import 'package:flutter_credit_card/flutter_credit_card.dart';

void main() => runApp(MySample());
Expand Down
23 changes: 19 additions & 4 deletions lib/credit_card_background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ class CardBackground extends StatelessWidget {
const CardBackground({
Key? key,
required this.backgroundGradientColor,
required this.backgroundImage,
this.backgroundImage,
this.backgroundNetworkImage,
required this.child,
this.width,
this.height,
this.glassmorphismConfig,
}) : super(key: key);
}) : assert(
(backgroundImage == null && backgroundNetworkImage == null) ||
(backgroundImage == null && backgroundNetworkImage != null) ||
(backgroundImage != null && backgroundNetworkImage == null),
"You can't use network image & asset image at same time for card background"),
super(key: key);

final String? backgroundImage;
final String? backgroundNetworkImage;
final Widget child;
final Gradient backgroundGradientColor;
final Glassmorphism? glassmorphismConfig;
Expand All @@ -42,14 +49,22 @@ class CardBackground extends StatelessWidget {
gradient: glassmorphismConfig != null
? glassmorphismConfig!.gradient
: backgroundGradientColor,
image: backgroundImage != null
image: backgroundImage != null && backgroundImage!.isNotEmpty
? DecorationImage(
image: ExactAssetImage(
backgroundImage!,
),
fit: BoxFit.fill,
)
: null,
: backgroundNetworkImage != null &&
backgroundNetworkImage!.isNotEmpty
? DecorationImage(
image: NetworkImage(
backgroundNetworkImage!,
),
fit: BoxFit.fill,
)
: null,
),
width: width ?? screenWidth,
height: height ??
Expand Down
2 changes: 1 addition & 1 deletion lib/credit_card_brand.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter_credit_card/flutter_credit_card.dart';

class CreditCardBrand {
CardType? brandName;

CreditCardBrand(this.brandName);
CardType? brandName;
}
12 changes: 7 additions & 5 deletions lib/credit_card_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,9 @@ class _CreditCardWidgetState extends State<CreditCardWidget>
}

Widget getCardTypeImage(CardType? cardType) {
final List<CustomCardTypeIcon> customCardTypeIcon = getCustomCardTypeIcon(cardType!);
if(customCardTypeIcon.isNotEmpty){
final List<CustomCardTypeIcon> customCardTypeIcon =
getCustomCardTypeIcon(cardType!);
if (customCardTypeIcon.isNotEmpty) {
return customCardTypeIcon.first.cardImage;
} else {
return Image.asset(
Expand All @@ -552,12 +553,13 @@ class _CreditCardWidgetState extends State<CreditCardWidget>
}
}

// This method returns the icon for the visa card type if found
// else will return the empty container
// This method returns the icon for the visa card type if found
// else will return the empty container
Widget getCardTypeIcon(String cardNumber) {
Widget icon;
final CardType ccType = detectCCType(cardNumber);
final List<CustomCardTypeIcon> customCardTypeIcon = getCustomCardTypeIcon(ccType);
final List<CustomCardTypeIcon> customCardTypeIcon =
getCustomCardTypeIcon(ccType);
if (customCardTypeIcon.isNotEmpty) {
icon = customCardTypeIcon.first.cardImage;
isAmex = ccType == CardType.americanExpress;
Expand Down
2 changes: 1 addition & 1 deletion lib/flutter_credit_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ library flutter_credit_card;
export 'credit_card_form.dart';
export 'credit_card_model.dart';
export 'credit_card_widget.dart';
export 'glassmorphism_config.dart';
export 'custom_card_type_icon.dart';
export 'glassmorphism_config.dart';
2 changes: 0 additions & 2 deletions lib/glassmorphism_config.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:ui';

import 'package:flutter/material.dart';

class Glassmorphism {
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.1

flutter:
assets:
Expand Down
2 changes: 1 addition & 1 deletion test/localized_text_model_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_credit_card/localized_text_model.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
test('Object correctly instantiated with properties', () {
Expand Down

0 comments on commit 65094b5

Please sign in to comment.