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

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

example/lib/main.dart

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

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

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

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

class _MyAppState extends State<MyApp> {
  CardScanResult? _scanResult;
  String? _error;

  Future<void> _startScan(BuildContext context) async {
    final result = await Navigator.push<CardScanResult?>(context, MaterialPageRoute(builder: (context) => ScanPage()));
    if (result != null) {
      setState(() {
        _scanResult = result;
        _error = null;
      });
    } else {
      setState(() {
        _error = 'No card scanned.';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Builder(
        builder: (context) {
          return Scaffold(
            appBar: AppBar(title: const Text('Card Scanner Plus')),
            body: Center(
              child: Padding(
                padding: const EdgeInsets.all(24),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    ElevatedButton(onPressed: () => _startScan(context), child: Text('Scan Card')),
                    const SizedBox(height: 24),
                    if (_scanResult != null) ...[
                      const Text('Card number:', style: TextStyle(fontWeight: FontWeight.bold)),
                      Text(_scanResult!.cardNumber),
                      const SizedBox(height: 12),
                      if (_scanResult!.expiryMonth != null && _scanResult!.expiryYear != null)
                        Text(
                          'Expiry: ${_scanResult!.expiryMonth!.toString().padLeft(2, '0')}/'
                          '${_scanResult!.expiryYear}',
                        ),
                    ] else
                      const Text('Tap the button to scan a card.'),
                    if (_error != null) ...[
                      const SizedBox(height: 24),
                      Text(_error!, style: const TextStyle(color: Colors.red)),
                    ],
                  ],
                ),
              ),
            ),
          );
        },
      ),
    );
  }
}
0
likes
140
points
42
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

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

Homepage

License

MIT (license)

Dependencies

camera, flutter, google_mlkit_text_recognition

More

Packages that depend on card_scanner_plus