Skip to main content

card_scanner_plus 0.1.1 copy "card_scanner_plus: ^0.1.1" to clipboard
card_scanner_plus: ^0.1.1 copied to clipboard

Flutter-only card scanning experience powered by Camera and ML Kit.

card_scanner_plus #

A bank card scanner written only in Flutter. It uses the camera package and Google ML Kit text recognition to read the card number and expiry date from a live camera feed, so you write no platform code of your own.

Features #

  • Live scanning from the back camera. The scanner stops by itself as soon as it finds a valid card.
  • Card number detection (13–19 digits), checked with the Luhn algorithm.
  • Expiry date detection from MM/YY or MM/YYYY text.
  • An overlay with a highlighted card frame.
  • A built-in flashlight (torch) toggle.
  • Your own hint text, text style and flash icon.

Requirements #

Platform Minimum
Android minSdk 21
iOS 15.5 (64-bit devices only)

Installation #

dependencies:
  card_scanner_plus: ^0.1.1

iOS #

Add a camera usage description to ios/Runner/Info.plist:

<key>NSCameraUsageDescription</key>
<string>The camera is used to scan your bank card.</string>

Set the minimum platform in ios/Podfile:

platform :ios, '15.5'

ML Kit does not support 32-bit architectures. If flutter build ios fails, exclude armv7 in Xcode. The ML Kit iOS notes explain how.

Android #

In android/app/build.gradle, make sure minSdk is at least 21:

defaultConfig {
    minSdk = 21
}

The camera plugin adds the camera permission to the manifest for you.

Usage #

import 'package:card_scanner_plus/card_scanner_plus.dart';
import 'package:flutter/material.dart';

class ScanPage extends StatelessWidget {
  const ScanPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Scan card')),
      body: CardScannerWidget(
        onScanned: (result) => Navigator.pop(context, result),
      ),
    );
  }
}

Open the page and wait for the result:

final result = await Navigator.push<CardScanResult?>(
  context,
  MaterialPageRoute(builder: (_) => const ScanPage()),
);

if (result != null) {
  print(result.cardNumber);   // e.g. 4111111111111111
  print(result.expiryMonth);  // e.g. 12 (may be null)
  print(result.expiryYear);   // e.g. 27 (may be null)
}

Customization #

CardScannerWidget(
  onScanned: (result) { /* ... */ },
  description: 'Place the card inside the frame',
  descriptionTextStyle: const TextStyle(color: Colors.white, fontSize: 16),
  flashIcon: const Icon(Icons.flash_on, color: Colors.black),
)

API #

CardScannerWidget #

Parameter Type Default Description
onScanned ValueChanged<CardScanResult> required Called once, when a valid card is found.
description String? built-in hint Hint text shown above the frame.
descriptionTextStyle TextStyle? bodyMedium, white Style of the hint text.
flashIcon Widget? flashlight icon Icon inside the flash toggle button.
enableFlash bool true Shows the flash toggle.

CardScanResult #

Field Type Description
cardNumber String Card number, digits only.
expiryMonth int? Expiry month (1–12), if found.
expiryYear int? Expiry year as printed on the card (27 or 2027), if found.

Notes #

  • Text recognition runs on the device. No images or card data leave the phone.
  • Frames are analysed about every 400 ms, which keeps CPU use low.
  • expiryMonth and expiryYear can be null if the date was not readable. In that case, ask the user to enter it by hand.

Example #

A full example app is in the example folder.

License #

MIT

1
likes
0
points
768
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter-only card scanning experience powered by Camera and ML Kit.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

camera, flutter, google_mlkit_text_recognition

More

Packages that depend on card_scanner_plus