nimr77 / Flutter_credit_card_scanner

A Flutter package that utilizes the device camera to scan and extract credit card information, providing a seamless and efficient way to capture card details in mobile applications.
MIT License
2 stars 0 forks source link

Error when running pod install when updating firebase packages #1

Closed ennesdes closed 1 day ago

ennesdes commented 3 days ago

I used the credit_card_scanner package in my project, but when I updated the Firebase packages to get the iOS push back to work, which were not working, there was an error when performing pod install, so I decided to use the flutter_credit_card_scanner package, which is updated more frequently, but The pod install error occurred again, can anyone check?

WhatsApp Image 2024-11-11 at 08 51 36

nimr77 commented 3 days ago

Hi This issue is related to Firebase messaging with the Google ML Data Transporter, to fix that you can change the Firebase version or update the plugin to 0.11.1

nimr77 commented 3 days ago

try use

firebase_core : ^2.15.1
firebase_messaging: ^14.6.7
ennesdes commented 3 days ago

flutter_credit_card_scanner: ^0.11.1

firebase_analytics: ^11.3.4 firebase_core: ^3.7.0 firebase_crashlytics: ^4.1.4 firebase_messaging: ^15.1.4 flutter_local_notifications: ^18.0.0

With these package versions, there are now no problems with pod install, thank you very much!

ennesdes commented 3 days ago

But I'm having a problem receiving the iOS push again

I tried using the versions you recommended, but it causes more conflicts

nimr77 commented 2 days ago

can you share the new error you are getting

nimr77 commented 2 days ago

if you used version 0.11.1 of the plugin with the firebase versions I sent you, you will get errors, since it uses the latest google ML dependency

nimr77 commented 2 days ago

you will need to update the minimum deployment target to 15.5.0

ennesdes commented 1 day ago

I don't know exactly what happened, I cloned my Gitlab project again and added the changes to update the Firebase packages and started using your package, now the push is working, which wasn't on iOS before.

But I'm having trouble reading the card to get the correct flag.

Captura de Tela 2024-11-12 às 16 32 24

Before there was this logic, but with the update of the package to credit_card_type_detector: ^3.0.0 the list started to appear in place and the methods are not validating correctly, I thought about adding String validation with the type, but I'm not sure if it's correct and it also has a new matchStrength property which I'm also not sure what the numbers are for each type.

would you know the best way to get the flag

Another thing I'm having a problem with now, he reads it very quickly, as soon as he looks at the card and reads it, this is bad for reading the name, and he often gets the name on the wrong card, and it's already happened that get the expiration number in half too, but the number I saw is always getting right, I'm trying to set a delay, I even set it to get the card only after 3 similar readings, but it still got the wrong name, it didn't recognize it and it said It's not from my country

ennesdes commented 1 day ago
Captura de Tela 2024-11-12 às 17 20 14

I created this variable to control multiple readings, as it reads very quickly, sometimes it would read 2x and end up going back 2x screens

nimr77 commented 1 day ago

My boss saying it doesn't read fast enough XD, for the flag if you mean the credit card types icon, I used SVGs and used enum and functions just to detect the type based on that I change the icon of the credit card type, so I'm glad that the scanner is working perfectly for you, I will close this issue now, since it was an issue with firebase and google ML,

import 'package:credit_card_type_detector/constants.dart';
import 'package:credit_card_type_detector/models.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';

/// Returns a list of [Widget]s displaying all supported credit card type icons.
///
/// This method maps through all credit card types defined in [CreditCardIconTypeWidget.iconMaptype]
/// and creates a widget for each type.
///
/// @param context The build context
/// @return List<Widget> A list of credit card type icon widgets
List<Widget> buildAllTypes(BuildContext context) {
  return CreditCardIconTypeWidget.iconMaptype.keys.map((e) {
    return CreditCardIconTypeWidget(
      type: e,
    );
  }).toList();
}

/// Builds a widget displaying a security code location hint image.
///
/// Creates an SVG image widget showing where the security code (CVV/CVC)
/// is located on the credit card based on the provided location.
///
/// @param context The build context
/// @param location The [SecurityCodeLocation] indicating whether the code is on front or back
/// @return Widget An SVG image widget showing the security code location hint
Widget buildCreditCardSecurtyCodeHint(
    BuildContext context, SecurityCodeLocation location,
    {Key? key}) {
  return SvgPicture.asset(
    location.hintSVG,
    key: key,
    width: CreditCardIconTypeWidget.ccIconSize,
    height: CreditCardIconTypeWidget.ccIconSize,
  );
}

/// Determines the location of the security code (CVV/CVC) on a credit card based on the card number prefix.
///
/// The security code can be located either on the front or back of the card depending on the card type:
/// - American Express (prefix 34, 37): Security code is on the front
/// - Visa (prefix 4): Security code is on the back
/// - Mastercard (prefix 51-55): Security code is on the back
/// - All other card types: Security code is assumed to be on the back
///
/// @param cardNumber The credit card number to analyze
/// @return SecurityCodeLocation indicating whether the code is on the front or back
SecurityCodeLocation determineSecurityCodeLocation(String cardNumber) {
  if (cardNumber.isEmpty) {
    return SecurityCodeLocation.back;
  }

  String prefix = cardNumber[0];

  switch (prefix) {
    case '3':
      return SecurityCodeLocation.front;

    case '4':
      return SecurityCodeLocation.back;

    case '5':
      return SecurityCodeLocation.back;

    default:
      return SecurityCodeLocation.back;
  }
}

/// A widget that displays a credit card icon based on the card type.
///
/// This widget renders SVG icons for different credit card types like Visa, Amex,
/// Mastercard, etc. If no specific type is provided or recognized, it falls back
/// to a default credit card icon.
///
/// The [iconMaptype] provides a mapping between card types and their corresponding
/// SVG asset paths.
///
/// Example:
///
/// CreditCardIconTypeWidget(
///   currType: CreditCardType.visa,
///   type: TYPE_VISA,
/// )
///
class CreditCardIconTypeWidget extends StatelessWidget {
  /// The standard size for credit card icons
  static const double ccIconSize = 20;

  /// Maps credit card types to their corresponding SVG asset paths
  static Map<String, String> get iconMaptype => {
        TYPE_VISA: "assets/icons/cards/visa.svg",
        TYPE_AMEX: "assets/icons/cards/ame.svg",
        TYPE_MAESTRO: "assets/icons/cards/mestro.svg",
        TYPE_MASTERCARD: "assets/icons/cards/master.svg",
        TYPE_DISCOVER: "assets/icons/cards/discover.svg",
        TYPE_DINERS_CLUB: "assets/icons/cards/dinnerClub.svg",
        TYPE_JCB: "assets/icons/cards/jcb.svg",
      };

  /// The current credit card type enum value
  final CreditCardType? currType;

  /// The credit card type as a string
  final String? type;

  /// Creates a credit card icon widget.
  ///
  /// Both [currType] and [type] are optional. If neither is provided,
  /// a default credit card icon will be shown.
  const CreditCardIconTypeWidget({super.key, this.currType, this.type});

  @override
  Widget build(BuildContext context) {
    Widget icon = SvgPicture.asset(
      iconMaptype[type] ??
          iconMaptype[currType?.type] ??
          "assets/icons/cards/creditCard_info.svg",
      width: ccIconSize,
      height: ccIconSize,
    );

    return icon;
  }
}

/// Represents the location of the security code on a credit card.
///
/// The security code (CVV/CVC) can be located either on the front
/// or back of the credit card depending on the card type.
enum SecurityCodeLocation {
  /// Security code is on the front of the card (e.g., American Express)
  front,

  /// Security code is on the back of the card (e.g., Visa, Mastercard)
  back;

  /// Returns the SVG asset path for the security code location hint image.
  String get hintSVG {
    switch (this) {
      case SecurityCodeLocation.front:
        return "assets/icons/cards/creditCard_front_code.svg";
      case SecurityCodeLocation.back:
        return "assets/icons/cards/creditCard_back_code.svg";
    }
  }

  /// Returns the SVG widget  for the security code location hint image.
  Widget getHint(BuildContext context, {Key? key}) =>
      buildCreditCardSecurtyCodeHint(context, this, key: key);

  /// Determines the security code location based on the provided card number.
  static SecurityCodeLocation getFromCode(String code) =>
      determineSecurityCodeLocation(code);
}

I hope this code will help you in the credit card type detector