hypersnapsdk_flutter 5.1.0
hypersnapsdk_flutter: ^5.1.0 copied to clipboard
HyperSnapSDK is HyperVerge's documents + face capture SDK that captures images at a resolution appropriate for our OCR and Face Recognition AI Engines.
example/lib/main.dart
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:hypersnapsdk_flutter/hypersnapsdk_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String faceImageUri = "";
String docImageUri = "";
@override
void initState() {
initHyperSnapSDK();
super.initState();
}
Future<void> initHyperSnapSDK() async {
String appId = "<your-app-id>";
String appKey = "<your-app-key>";
var initStatus = await HyperSnapSDK.initialize(
appId,
appKey,
Region.india,
);
log("hypersnapsdk initialisation status : $initStatus");
/// If you need to customise HyperSnapSDK Config
await HyperSnapSDK.setHyperSnapSDKConfig(
hyperSnapSDKConfig: HyperSnapSDKConfig(
// <your-hypersnapsdk-config>
),
);
}
/// Start user session
Future<void> startUserSession() async {
bool isStarted = await HyperSnapSDK.startUserSession('<session-id>');
log("start user session status : $isStarted");
}
/// End user session
Future<void> endUserSession() async {
await HyperSnapSDK.endUserSession();
}
/// Start Document Capture Flow
Future<void> startDocCapture() async {
await HVDocsCapture.start(
hvDocConfig: HVDocConfig(
// <your-doc-capture-config>
),
onComplete: (hvResponse, hvError) {
// Handle Doc Capture flow response / error
// ...
printResult(hvResponse, hvError);
setState(() {
docImageUri = hvResponse?.imageUri ?? "";
});
},
);
}
/// Start Face Capture Flow
Future<void> startFaceCapture() async {
await HVFaceCapture.start(
hvFaceConfig: HVFaceConfig(
// <your-face-capture-config>
),
onComplete: (hvResponse, hvError) {
// Handle Face Capture flow response / error
// ...
printResult(hvResponse, hvError);
setState(() {
faceImageUri = hvResponse?.imageUri ?? "";
});
},
);
}
/// Start Barcode Capture Flow
Future<void> barcodeScanCapture() async {
await HVBarcodeScanCapture.start(
hvBarcodeConfig: HVBarcodeConfig(
// <your-barcode-capture-config>
),
onComplete: (hvResult, hvError) {
// Handle Barcode Capture flow response / error
// ...
if (hvResult != null) {
log('barcode result : $hvResult');
}
if (hvError != null) {
log("error code : ${hvError.errorCode}");
log("error message : ${hvError.errorMessage}");
}
},
);
}
// Make OCR call using HVNetworkHelper utility class
Future<void> ocrCall() async {
await HVNetworkHelper.makeOCRCall(
endpoint: '<your-ocr-endpoint>',
documentUri: docImageUri/*<your-doc-image-uri>*/,
parameters: {},
headers: {},
onComplete: (hvResponse, hvError) {
// Handle OCR API Call response / error
// ...
printResult(hvResponse, hvError);
},
);
}
Future<void> faceMatchCall() async {
await HVNetworkHelper.makeFaceMatchCall(
endpoint: '<your-face-match-endpoint>',
faceUri: faceImageUri/*<your-face-image-uri>*/,
documentUri: docImageUri/*<your-doc-image-uri>*/,
faceMatchMode: FaceMatchMode.faceId,
parameters: {},
headers: {},
onComplete: (hvResponse, hvError) {
// Handle OCR API Call response / error
// ...
printResult(hvResponse, hvError);
},
);
}
void printResult(HVResponse? hvResponse, HVError? hvError) {
if (hvResponse != null) {
if (hvResponse.imageUri != null)
log("image uri : ${hvResponse.imageUri!}");
if (hvResponse.videoUri != null)
log("video uri : ${hvResponse.videoUri!}");
if (hvResponse.fullImageUri != null)
log("full image uri : ${hvResponse.fullImageUri!}");
if (hvResponse.retakeMessage != null)
log("retake Message : ${hvResponse.retakeMessage!}");
if (hvResponse.action != null) log("action : ${hvResponse.action!}");
if (hvResponse.apiResult != null)
log("api result : ${hvResponse.apiResult!.toString()}");
if (hvResponse.apiHeaders != null)
log("api headers : ${hvResponse.apiHeaders!.toString()}");
if (hvResponse.rawBarcode != null)
log("rawBarcode : ${hvResponse.rawBarcode!}");
}
if (hvError != null) {
log("error code : ${hvError.errorCode}");
log("error message : ${hvError.errorMessage}");
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text("HyperSnap Flutter Example"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () async => await startUserSession(),
child: Text("Start User Session"),
),
ElevatedButton(
onPressed: () async => await endUserSession(),
child: Text("End User Session"),
),
ElevatedButton(
onPressed: () async => await startDocCapture(),
child: const Text("Start Document Capture Flow"),
),
ElevatedButton(
onPressed: () async => await startFaceCapture(),
child: const Text("Start Face Capture Flow"),
),
ElevatedButton(
onPressed: () async => await barcodeScanCapture(),
child: const Text("Start Barcode Capture Flow"),
),
ElevatedButton(
onPressed: () async => await ocrCall(),
child: const Text("Make OCR Call"),
),
ElevatedButton(
onPressed: () async => await faceMatchCall(),
child: const Text("Make Face Match Call"),
),
],
),
),
),
);
}
}