itc_card_scanner 0.0.2 copy "itc_card_scanner: ^0.0.2" to clipboard
itc_card_scanner: ^0.0.2 copied to clipboard

A Flutter plugin for scanning credit cards using device camera with OCR. Extracts card number, expiry date, cardholder name, and card type.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:itc_card_scanner/itc_card_scanner.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _scanResult = 'No scan result yet';
  final _itcCardScannerPlugin = ItcCardScanner();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await _itcCardScannerPlugin.getPlatformVersion() ??
          'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  Future<void> _scanCard() async {
    try {
      final result = await _itcCardScannerPlugin.scanCard();

      if (result != null) {
        final cardDetails = ScannedCardDetails.fromMap(result);

        setState(() {
          _scanResult =
              '''
Scan Success: ${cardDetails.success}
Card Number: ${cardDetails.cardNumber}
Expiry Date: ${cardDetails.expiryDate}
Cardholder Name: ${cardDetails.cardholderName}
Card Type: ${cardDetails.cardType}
''';
        });
      } else {
        setState(() {
          _scanResult = 'Scan cancelled or failed';
        });
      }
    } catch (e) {
      setState(() {
        _scanResult = 'Error: $e';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('ITC Card Scanner Test'),
          backgroundColor: Colors.blue,
        ),
        body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Text(
                'Running on: $_platformVersion\n',
                style: const TextStyle(fontSize: 16),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                onPressed: _scanCard,
                style: ElevatedButton.styleFrom(
                  backgroundColor: Colors.green,
                  padding: const EdgeInsets.all(16),
                ),
                child: const Text(
                  'SCAN CARD',
                  style: TextStyle(fontSize: 18, color: Colors.white),
                ),
              ),
              const SizedBox(height: 20),
              Container(
                padding: const EdgeInsets.all(16),
                decoration: BoxDecoration(
                  border: Border.all(color: Colors.grey),
                  borderRadius: BorderRadius.circular(8),
                ),
                child: Text(_scanResult, style: const TextStyle(fontSize: 14)),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
0
points
21
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for scanning credit cards using device camera with OCR. Extracts card number, expiry date, cardholder name, and card type.

Topics

#camera #credit-card #scanner #ocr #payment

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on itc_card_scanner

Packages that implement itc_card_scanner