insurance_card_scanner 1.0.1 insurance_card_scanner: ^1.0.1 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.
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 = 'xxx';
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(
sessionToken: token,
live: false,
onSuccess: (card) {
debugPrint("Scanned card: $card");
showMessage(context, 'Scan success');
},
onError: (message) {
showMessage(context, message ?? '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: Colors.purple,
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(
sessionToken: token,
live: false,
onSuccess: (card) {
debugPrint("Scanned card: $card");
showMessage(context, 'Scan success');
},
onError: (message) {
showMessage(context, message ?? 'Scan failed');
},
onWebViewLoadError: () {
showMessage(context, 'WebView failed to load');
},
onCancel: Navigator.of(context).pop,
autoSwitchActiveColor: Colors.purple,
progressBarColor: Colors.purple,
widgetBackgroundColor: Colors.purple,
autoSwitchInactiveColor: Colors.purple,
backsideSupport: true,
messageStyle: const TextStyle(
fontSize: 70,
color: Colors.purple,
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"),
)
],
),
);
}