hypersnapsdk_flutter 0.0.2
hypersnapsdk_flutter: ^0.0.2 copied to clipboard
Flutter Plugin for HyperSnap SDK
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:hypersnapsdk_flutter/hypersnapsdk_flutter.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String imagePath = "images/flutter-logo.png";
@override
void initState() {
super.initState();
initHyperSnapSDK();
}
/// Initialises the HyperSnapSDK
void initHyperSnapSDK() async {
// TODO: Add appId and appKey
HyperSnapSDKFlutter.initialize(
"", "", (await HyperSnapSDKFlutter.getValidParams())["RegionIndia"]);
}
/// Opens document capture screen
void openDocumentCaptureScreen() async {
Map docCaptureMap = await HyperSnapSDKFlutter.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"]);
setState(() {
imagePath = docResultObj["imageUri"];
});
}
}
/// Opens face capture screen
void openFaceCaptureScreen() async {
Map faceCaptureMap = await HyperSnapSDKFlutter.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"]);
setState(() {
imagePath = faceResultObj["imageUri"];
});
}
}
/// Opens QR scanner screen
void openQRScanner() async {
Map map = await HyperSnapSDKFlutter.qrScanCaptureStart();
debugPrint("QR Scan result - " + map.toString());
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('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();
},
),
),
])),
),
));
}
}