Skip to content

Commit

Permalink
Fix Safari (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilonik authored Jul 25, 2022
1 parent a6bfbb8 commit 807cd33
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/credit_card_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,21 @@ class _CreditCardWidgetState extends State<CreditCardWidget>
),
);

final String number = widget.obscureCardNumber
? widget.cardNumber.replaceAll(RegExp(r'(?<=.{4})\d(?=.{4})'), '*')
: widget.cardNumber;
String number = widget.cardNumber;
if (widget.obscureCardNumber) {
final String stripped = number.replaceAll(RegExp(r'[^\d]'), '');
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);
}
}
return CardBackground(
backgroundImage: widget.backgroundImage,
backgroundGradientColor: backgroundGradientColor,
Expand Down

0 comments on commit 807cd33

Please sign in to comment.