Our `CardScanner` Flutter widget makes it easy to add insurance card scanning to any Flutter application in 5 minutes or less.

## Compatibility

|             | Android | iOS   |
| ----------- | ------- | ----- |
| **Support** | 5.0+    | 12.0+ |

#

## Installation

Add the `insurance_card_scanner` package to your `pubspec.yaml` file.

```yaml
dependencies:
  flutter:
    sdk: flutter
  insurance_card_scanner: ^1.1.0
```

Or, run the following command:

```
flutter pub add insurance_card_scanner
```

#

## Usage

Import the library widget into your project files:

```dart
import 'package:insurance_card_scanner/insurance_card_scanner.dart';
```

You can **optionally** add the API client for more custom applications.

```dart
import 'package:insurance_card_scanner/insurance_card_scanner_api.dart';
```

This package relies on the CardScan AI for scanning and capturing data from insurance cards. For complete understand of package setup and usage, you can refer to the [package docs](https://docs.cardscan.ai/ui-components/flutter).

For a list of steps for configuring insurance card scanner, see the [example app README](https://github.com/CardScan-ai/insurance_card_scanner/blob/main/example/README.md).

#

## Getting started

### Android camera permissions

Add the following line to your AndroidManifest.xml file:

```xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIDEO_CAPTURE" />
```

### iOS camera permissions

Add the following lines to your Info.plist file:

```xml
<key>NSCameraUsageDescription</key>
<string>Your description of why you need access to camera</string>
<key>NSAppTransportSecurity</key>
<dict>
 <key>NSAllowsArbitraryLoadsInWebContent</key>
   <true/>
 <key>NSAllowsLocalNetworking</key>
      <true/>
</dict>
```

## Sandbox API Keys

Create a **free** account on the [dashboard](https://dashboard.cardscan.ai/onboarding) to generate a sandbox API key.

## Basic examples

### CardScanner widget

Use it on your custom screens like any other widget:

```dart
import 'package:insurance_card_scanner/insurance_card_scanner.dart';

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(
          sessionToken: '<pass your token here>',
          onSuccess: (card) {
            print('Scan success');
          },
          onError: (message) {
            print(message ?? 'Unknown Scan error');
          },
          onCancel: () {
            Navigator.of(context).pop();
          },
        ),
      ),
    );
  }
}
```

### CardScannerModal widget

Push it using Navigator to open a full-screen scanner.

```dart

Navigator.of(context).push(
  CardScanModal(
    properties: CardScanConfig(
      sessionToken: 'pass your token here',
      onSuccess: (card) {
        print('Scan success');
      },
      onError: (message) {
        print(message ?? 'Scan error');
      },
      onCancel: () {
        Navigator.of(context).pop();
      },
    ),
  ),
);

```

### Available Properties

Both `CardScanner` and `CardScannerModal` should be passed a `CardScanConfig` instance with properties for server connection, callback handling and UI customization.

```dart
CardScanConfig(
  // Required
  sessionToken: token,
  onSuccess: onSuccess,

  // Recommended
  onCancel: onCancel,
  onError: onError,
  live: live,

  // Optional
  backsideSupport: scanBackside,
  onRetry: onRetry,
  onWebViewLoadError: onWebViewLoadError,

  // UI Customization
  messages: messages,
  messageStyle: messagesStyle,
  autoSwitchActiveColor: autoSwitchActiveColor,
  autoSwitchInactiveColor: autoSwitchInactiveColor,
  progressBarColor: progressBarColor,
  widgetBackgroundColor: widgetBackgroundColor,
)
```

#

## Authentication

CardScan supports authentication for two different kinds of use cases:</br>

- [Server-to-server](https://docs.cardscan.ai/authentication#server-to-server) - backend systems, admin portals, etc.
- [End User](https://docs.cardscan.ai/authentication#end-user) - a patient or clinician most likely on mobile or the web.</br>

For detailed information on authentication and generating a JSON Web Token (JWT), check out the [authentication docs.](https://docs.cardscan.ai/authentication)

#

## Official documentation

For a complete understanding of package setup and usage, you can refer to the [package docs](https://docs.cardscan.ai/ui-components/flutter).
