hypersnapsdk_flutter 1.1.0 hypersnapsdk_flutter: ^1.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.
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:hypersnapsdk_flutter/HVDocsCapture.dart';
import 'package:hypersnapsdk_flutter/HVFaceCapture.dart';
import 'package:hypersnapsdk_flutter/HVHyperSnapParams.dart';
import 'package:hypersnapsdk_flutter/HVQRScanCapture.dart';
import 'package:hypersnapsdk_flutter/HyperSnapSDK.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String imagePath = "images/flutter-logo.png";
var documentUri = "";
var faceUri = "";
@override
void initState() {
super.initState();
initHyperSnapSDK();
}
/// Initialises the HyperSnapSDK
void initHyperSnapSDK() async {
// TODO: Add appId and appKey
var appID = "";
var appKey = "";
await HyperSnapSDK.initialize(appID, appKey,
(await HVHyperSnapParams.getValidParams())["RegionIndia"]);
}
/// Opens document capture screen
void openDocumentCaptureScreen() async {
Map docCaptureMap = await HVDocsCapture.docsCaptureStart();
Map docResultObj = docCaptureMap["resultObj"];
Map docErrorObj = docCaptureMap["errorObj"];
debugPrint("Results Map - " + docResultObj.toString());
debugPrint("Error Map - " + docErrorObj.toString());
if (docErrorObj.isNotEmpty) {
// Handle error
debugPrint(docErrorObj["errorMessage"]);
debugPrint(docErrorObj["errorCode"]?.toString());
} else {
// Handle success results
debugPrint(docResultObj["apiResult"]);
debugPrint(docResultObj["imageUri"]);
documentUri = docResultObj["imageUri"];
setState(() {
imagePath = docResultObj["imageUri"];
});
}
}
/// Opens face capture screen
void openFaceCaptureScreen() async {
Map faceCaptureMap = await HVFaceCapture.faceCaptureStart();
Map faceResultObj = faceCaptureMap["resultObj"];
Map faceErrorObj = faceCaptureMap["errorObj"];
debugPrint("Results Map - " + faceResultObj.toString());
debugPrint("Error Map - " + faceErrorObj.toString());
if (faceErrorObj.isNotEmpty) {
// Handle error
debugPrint(faceErrorObj["errorMessage"]);
debugPrint(faceErrorObj["errorCode"]?.toString());
} else {
// Handle success results
debugPrint(faceResultObj["apiResult"]);
debugPrint(faceResultObj["imageUri"]);
faceUri = faceResultObj["imageUri"];
setState(() {
imagePath = faceResultObj["imageUri"];
});
}
}
/// Opens QR scanner screen
void openQRScanner() async {
Map map = await HVQRScanCapture.qrScanCaptureStart();
debugPrint("QR Scan result - " + map.toString());
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('HyperSnapSDK Flutter Plugin example app'),
),
body: SingleChildScrollView(
child: Center(
child: Column(children: <Widget>[
Container(
margin: EdgeInsets.all(25),
),
Container(
margin: EdgeInsets.all(25),
child: MaterialButton(
child: Text(
"Open Docs Capture",
style: TextStyle(fontSize: 20.0),
),
color: Colors.blueAccent,
textColor: Colors.white,
onPressed: () async {
openDocumentCaptureScreen();
},
),
),
Container(
margin: EdgeInsets.all(25),
child: MaterialButton(
child: Text(
"Open face Capture",
style: TextStyle(fontSize: 20.0),
),
color: Colors.blueAccent,
textColor: Colors.white,
onPressed: () async {
openFaceCaptureScreen();
},
),
),
Container(
margin: EdgeInsets.all(25),
child: MaterialButton(
child: Text(
"Open QR Scan Capture",
style: TextStyle(fontSize: 20.0),
),
color: Colors.blueAccent,
textColor: Colors.white,
onPressed: () async {
openQRScanner();
},
),
),
Image.file(
File(imagePath),
)
])),
),
));
}
}