insurance_card_scanner 1.1.6 copy "insurance_card_scanner: ^1.1.6" to clipboard
insurance_card_scanner: ^1.1.6 copied to clipboard

A library that makes it easy to add insurance card scanning and eligibility verification to any flutter application in 5 minutes or less.

example/lib/main.dart

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

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  runApp(const MyApp());
}

// set a valid session token here
const token = String.fromEnvironment("CS_API_KEY", defaultValue: "");

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Card Scanner Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MainScreen(),
    );
  }
}

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

  void showWidget(BuildContext context) => Navigator.of(context).push(
        MaterialPageRoute(
          builder: (ctx) => const ScannerWidgetScreen(),
        ),
      );

  void showModal(BuildContext context) => Navigator.of(context).push(
        CardScannerModal(
          properties: CardScanConfig(
            logging: CardScanLogLevel.verbose,
            sessionToken: token,
            live: false,
            onSuccess: (card) {
              debugPrint("Scanned card: $card");
              showMessage(context, 'Scan success');
            },
            onError: (message) {
              showMessage(context, message?.toString() ?? 'Scan failed');
            },
            onWebViewLoadError: () {
              showMessage(context, 'WebView failed to load');
            },
            onCancel: Navigator.of(context).pop,
            autoSwitchActiveColor: Colors.purple,
            progressBarColor: Colors.purple,
            widgetBackgroundColor: Colors.purple,
            backsideSupport: true,
            messageStyle: const TextStyle(
              fontSize: 70,
              color: Color.fromARGB(255, 62, 176, 39),
              backgroundColor: Colors.white,
            ),
            messages: const CardScanMessages(
              autoCaptureTitle: 'autoCaptureTitle',
              cameraErrorTitle: 'cameraErrorTitle',
              completedTitle: 'completedTitle',
              errorTitle: 'errorTitle',
              frontSideCompletedTitle: 'frontsideCompletedTitle',
              manualCaptureTitle: 'manualCaptureTitle',
              processingTitle: 'processingTitle',
              retryTitle: 'retryTitle',
            ),
          ),
        ),
      );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Card Scanner Example'),
      ),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            MaterialButton(
              onPressed: () => showWidget(context),
              color: Colors.blue,
              textColor: Colors.white,
              child: const Text('Show widget'),
            ),
            const SizedBox(height: 40),
            MaterialButton(
              onPressed: () => showModal(context),
              color: Colors.green,
              textColor: Colors.white,
              child: const Text('Show modal'),
            )
          ],
        ),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Scanner widget'),
      ),
      body: CardScanner(
        properties: CardScanConfig(
          logging: CardScanLogLevel.off,
          eligibility: const EligibilityRequest(
              provider: Provider(
                  firstName: "TestProviderFirstName",
                  lastName: "TestProviderLastName",
                  npi:
                      "123456789"), // For a valid NPI, add a 3 to the right of 9
              subscriber: Subscriber(
                  firstName: "Walter",
                  lastName: "Witman",
                  dateOfBirth: "19020403")),
          onEligibilitySuccess: (eligibility) {
            showMessage(context, 'Eligibility success');
            debugPrint("Eligibility sucess: $eligibility");
          },
          onEligibilityError: (error) {
            showMessage(context, 'Eligibility error');
            debugPrint("Eligibility error: $error");
          },
          sessionToken: token,
          live: false,
          onSuccess: (card) {
            debugPrint("Scanned card: $card");
          },
          onError: (error) {
            showMessage(context, error?.message ?? 'Scan failed');
            debugPrint("Error: $error");
          },
          onWebViewLoadError: () {
            showMessage(context, 'WebView failed to load');
          },
          onCancel: Navigator.of(context).pop,
          autoSwitchActiveColor: Colors.blue,
          progressBarColor: Colors.blue,
          widgetBackgroundColor: Colors.purple,
          autoSwitchInactiveColor: Colors.blue,
          backsideSupport: false,
          messageStyle: const TextStyle(
            fontSize: 70,
            color: Colors.blue,
            backgroundColor: Colors.white,
          ),
          messages: const CardScanMessages(
            autoCaptureTitle: 'autoCaptureTitle',
            cameraErrorTitle: 'cameraErrorTitle',
            completedTitle: 'completedTitle',
            errorTitle: 'errorTitle',
            frontSideCompletedTitle: 'frontsideCompletedTitle',
            manualCaptureTitle: 'manualCaptureTitle',
            processingTitle: 'processingTitle',
            retryTitle: 'retryTitle',
          ),
        ),
      ),
    );
  }
}

void showMessage(BuildContext context, String message) {
  showDialog(
    context: context,
    builder: (ctx) => AlertDialog(
      title: Text(message),
      actions: [
        TextButton(
          onPressed: Navigator.of(context).pop,
          child: const Text("OK"),
        )
      ],
    ),
  );
}
2
likes
130
points
985
downloads

Publisher

verified publishercardscan.ai

Weekly Downloads

A library that makes it easy to add insurance card scanning and eligibility verification to any flutter application in 5 minutes or less.

Homepage

Documentation

Documentation
API reference

License

unknown (license)

Dependencies

built_value, cardscan_client, flutter, flutter_inappwebview, package_info_plus, permission_handler, pubspec_parse

More

Packages that depend on insurance_card_scanner