π³ Card Scanner Package for Flutter
A Flutter package that allows developers to scan credit/debit cards using the deviceβs camera and extract card numbers and expiry dates via Google ML Kit OCR.
π Features
- π· Uses the device camera (via
cameraplugin) - π€ Optical Character Recognition (OCR) powered by
google_ml_kit - π― Accurate extraction of:
- Card number (16 digits)
- Expiry date (MM/YY or MM/YYYY)
- π Automatically detects text and closes when valid data is found
- β Works on both Android & iOS
π¦ Installation
Add the following to your pubspec.yaml:
dependencies:
card_scannerr:
git:
url: https://github.com/brightroots7/card_scannerr
Then run:
flutter pub get
π οΈ Usage
1. Import the package
import 'package:card_scannerr/card_scannerr.dart';
2. Launch the scanner
final cardDetails = await startCardScanner(context);
if (cardDetails != null) {
print('Card Number: ${cardDetails.cardNumber}');
print('Expiry Date: ${cardDetails.expiryDate}');
}
β
Permissions
Android (android/app/src/main/AndroidManifest.xml)
<uses-permission android:name="android.permission.CAMERA" />
iOS (ios/Runner/Info.plist)
<key>NSCameraUsageDescription</key>
<string>This app needs camera access to scan your card.</string>
π Example
Hereβs a basic Flutter UI example that uses the package:
ElevatedButton(
onPressed: () async {
final result = await startCardScanner(context);
if (result != null) {
print(result.cardNumber);
print(result.expiryDate);
}
},
child: Text('Scan Card'),
)
π How It Works
Opens camera using camera plugin.
Streams camera frames to google_ml_kit's TextRecognizer.
Searches for card number & expiry pattern using RegEx.
Returns CardDetails and pops the scanner screen when found.
π§ Implementation Notes
Uses CameraImage β InputImage.fromBytes() for real-time processing.
Memory-optimized using a scan flag to avoid flooding the recognizer.
You can customize or extend the logic in CardParser.