hypersnapsdk_flutter 1.5.0 copy "hypersnapsdk_flutter: ^1.5.0" to clipboard
hypersnapsdk_flutter: ^1.5.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> {
  bool isUserSessionStarted = false;
  String faceImageUri = "";
  String docImageUri = "";

  @override
  void initState() {
    initHyperSnapSDK();
    super.initState();
  }

  initHyperSnapSDK() async {
    String appId = "abc"; //your app id
    String appKey = "abc"; //your app key

    var init = await HyperSnapSDK.initialize(appId, appKey, Region.india);
    log(init);
    await HyperSnapSDK.setHyperSnapSDKConfig(
      hyperSnapSDKConfig: HyperSnapSDKConfig(
          shouldEnableSSLPinning: true,
          timeoutConfig: HVTimeoutConfig(
              connectTimeout: 100, readTimeout: 100, writeTimeout: 100)),
    );
  }

  changeUserSessionStatus() async {
    if (!isUserSessionStarted) {
      await HyperSnapSDK.endUserSession();
      bool isStarted = await HyperSnapSDK.startUserSession('abc');
      if (isStarted) {
        isUserSessionStarted = isStarted;
      }
      log("user session started : $isUserSessionStarted");
    } else {
      await HyperSnapSDK.endUserSession();
      isUserSessionStarted = false;
    }
    setState(() {});
  }

  startDocCapture() async {
    await HVDocsCapture.start(
        hvDocConfig: HVDocConfig(),
        onComplete: (hvResponse, hvError) {
          printResult(hvResponse, hvError);
          setState(() {
            docImageUri = hvResponse?.imageUri ?? "";
          });
        });
  }

  startFaceCapture() async {
    await HVFaceCapture.start(
        hvFaceConfig: HVFaceConfig(),
        onComplete: (hvResponse, hvError) {
          printResult(hvResponse, hvError);
          setState(() {
            faceImageUri = hvResponse?.imageUri ?? "";
          });
        });
  }

  faceMatchCall() async {
    await HVNetworkHelper.makeFaceMatchCall(
        endpoint: "",
        //face match endpoint
        faceUri: faceImageUri,
        documentUri: docImageUri,
        faceMatchMode: FaceMatchMode.faceId,
        parameters: {},
        headers: {},
        onComplete: (hvResponse, hvError) {
          printResult(hvResponse, hvError);
        });
  }

  ocrCall() async {
    await HVNetworkHelper.makeOCRCall(
        endpoint: "",
        //OCR endpoint
        documentUri: docImageUri,
        parameters: {},
        headers: {},
        onComplete: (hvResponse, hvError) {
          printResult(hvResponse, hvError);
        });
  }

  barcodeScanCapture() async {
    await HVBarcodeScanCapture.start(
        hvBarcodeConfig: HVBarcodeConfig(),
        onComplete: (hvResponse, hvError) {
          printResult(hvResponse, hvError);
        });
  }

  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.qr != null) log("qr : ${hvResponse.qr!}");
    }
    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"),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                  onPressed: () async => await changeUserSessionStatus(),
                  child: Text(
                      isUserSessionStarted ? "end session" : "start session")),
              ElevatedButton(
                  onPressed: () async => await startDocCapture(),
                  child: const Text("start doc capture")),
              ElevatedButton(
                  onPressed: () async => await startFaceCapture(),
                  child: const Text("start face capture")),
              ElevatedButton(
                  onPressed: () async => await faceMatchCall(),
                  child: const Text("start face match ")),
              ElevatedButton(
                  onPressed: () async => await ocrCall(),
                  child: const Text("start ocr call ")),
              ElevatedButton(
                  onPressed: () async => await barcodeScanCapture(),
                  child: const Text("start qr scan ")),
            ],
          ),
        ),
      ),
    );
  }
}
11
likes
0
pub points
89%
popularity

Publisher

unverified uploader

HyperSnapSDK is HyperVerge's documents + face capture SDK that captures images at a resolution appropriate for our OCR and Face Recognition AI Engines.

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on hypersnapsdk_flutter