blusalt_liveness_native 0.1.25 copy "blusalt_liveness_native: ^0.1.25" to clipboard
blusalt_liveness_native: ^0.1.25 copied to clipboard

Liveness SDK for Android and IOS

example/lib/main.dart

import 'dart:convert';

import 'package:blusalt_liveness_native/enums.dart';
import 'package:blusalt_liveness_native/liveness.dart';
import 'package:blusalt_liveness_native/model.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';

import 'base64image.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _livenessPlugin = BlusaltLivenessNative();

  final String clientId = "errereere";
  final String appName = "errerere";
  final String apiKey = "errerererere";
  final bool isDev = false;

  // If you want to start the DK on getting to the SDK homepage rather than making user click continue button
  final bool startProcessOnGettingToFirstScreen = false;

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

  Future<BlusaltLivenessResultResponse?> faceComparison() async {
    final Uint8List decodedBytes = base64Decode(base64String);
    BlusaltLivenessResultResponse? response =
        await _livenessPlugin.startFacialComparisonSDK(
            apiKey: apiKey,
            appName: appName,
            clientId: clientId,
            isDev: isDev,
            imageData: decodedBytes,
            startProcessOnGettingToFirstScreen:
                startProcessOnGettingToFirstScreen);
    if (response?.livenessResultType == BlusaltLivenessResultType.success) {
      //   Face comparison is successful
      String? originalImagePassedToSDKInBase64 =
          response?.comparisonData?.originalImage;
      bool isFaceComparisonPassed =
          response?.comparisonData?.isPassFaceComparison ?? false;

      String? livnessImageInBase64 = response?.faceDetectionData?.imageByte;
      bool isLivnessPassed =
          response?.faceDetectionData?.isPassFaceGenuiness ?? false;
    } else {
      //   Face comparison failed
      debugPrint(response?.code ?? '');
      debugPrint(response?.message ?? '');
    }
    return response;
  }

  Future<BlusaltLivenessResultResponse?> livenessDetection() async {
    BlusaltLivenessResultResponse? response =
        await _livenessPlugin.startLivenessDetectionOnlySDK(
            apiKey: apiKey,
            appName: appName,
            clientId: clientId,
            isDev: isDev,
            startProcessOnGettingToFirstScreen:
                startProcessOnGettingToFirstScreen);

    if (response?.livenessResultType == BlusaltLivenessResultType.success) {
      //   Liveness detection is successful
      String? livnessImageInBase64 = response?.faceDetectionData?.imageByte;
      bool isLivnessPassed =
          response?.faceDetectionData?.isPassFaceGenuiness ?? false;
    } else {
      //   Liveness detection failed
      debugPrint(response?.code ?? '');
      debugPrint(response?.message ?? '');
    }
    return response;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Click button to start liveness'),
            TextButton(
                onPressed: () {
                  faceComparison();
                },
                child: Text('Start Facial Comparison')),
            SizedBox(
              height: 24,
            ),
            TextButton(
                onPressed: () {
                  livenessDetection();
                },
                child: Text('Start Face Detection Only'))
          ],
        ),
      ),
    );
  }
}
2
likes
140
points
35
downloads

Publisher

unverified uploader

Weekly Downloads

Liveness SDK for Android and IOS

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, flutter_web_plugins

More

Packages that depend on blusalt_liveness_native