awesome_mobile_scanner 0.0.4

SDKflutter
Platformandroidiosmacosweb

A universal Flutter barcode and QR code scanner using CameraX/ML Kit for Android, AVFoundation/Apple Vision for iOS & macOS, and ZXing for web.

Credit Card Scanner Screen

The CreditCardScannerScreen is a pre-built, customizable screen for scanning credit cards using the awesome_mobile_scanner package.

Features

  • Automatic Detection: Automatically detects credit cards using OCR
  • Customizable UI: Fully customizable colors, sizes, and styling
  • Confidence Threshold: Configurable confidence threshold for detection
  • Auto-formatting: Automatically formats card numbers with spaces
  • Auto-close: Automatically closes when a card is detected with high confidence

Usage

Basic Usage

import 'package:awesome_mobile_scanner/awesome_mobile_scanner.dart';

// Navigate to the scanner
Navigator.of(context).push(
  MaterialPageRoute(
    builder: (context) => CreditCardScannerScreen(
      onCardDetected: (String cardNumber) {
        // Handle the detected card number
        print('Detected card: $cardNumber');
        Navigator.pop(context);
      },
    ),
  ),
);

Advanced Usage with Customization

CreditCardScannerScreen(
  onCardDetected: (String cardNumber) {
    // Handle the detected card number
    setState(() {
      _scannedCardNumber = cardNumber;
    });
    Navigator.pop(context);
  },
  appBar: AppBar(
    title: const Text('Scan Credit Card'),
    backgroundColor: Colors.transparent,
    foregroundColor: Colors.white,
    elevation: 0,
  ),
  backgroundColor: Colors.black,
  overlayColor: Colors.black.withValues(alpha: 0.3),
  borderColor: Colors.white,
  scanAreaWidth: MediaQuery.of(context).size.width * 0.85,
  scanAreaHeight: MediaQuery.of(context).size.height * 0.30,
  borderWidth: 2.0,
  borderRadius: 12.0,
  confidenceThreshold: 0.7,
)

Parameters

ParameterTypeDefaultDescription
onCardDetectedFunction(String)RequiredCallback when a card is detected
appBarPreferredSizeWidget?nullCustom app bar widget
backgroundColorColor?Colors.blackBackground color of the screen
overlayColorColor?Colors.black.withValues(alpha: 0.3)Color of the overlay outside scan area
borderColorColor?Colors.whiteColor of the scanning area border
scanAreaWidthdouble?width * 0.85Width of the scanning area
scanAreaHeightdouble?height * 0.30Height of the scanning area
borderWidthdouble?2.0Width of the scanning area border
borderRadiusdouble?12.0Border radius of the scanning area
confidenceThresholddouble0.7Minimum confidence required for detection

How it Works

  1. The screen initializes a MobileScannerController with DetectionType.creditCard
  2. When a credit card is detected, it checks the confidence level
  3. If confidence is above the threshold, it formats the card number and calls onCardDetected
  4. The screen automatically closes after a 1-second delay to show the detected card

Example

See example/lib/screens/credit_card_scanner_example.dart for a complete working example.