blusalt_liveness_native 0.1.5 copy "blusalt_liveness_native: ^0.1.5" to clipboard
blusalt_liveness_native: ^0.1.5 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 = "";
  final String appName = "";
  final String apiKey = "";
  final bool isDev = false;

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

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

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

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

      Uint8List? livnessImage = response?.faceDetectionData?.imageByte;
      bool isLivnessPassed =
          response?.faceDetectionData?.isPassFaceGenuiness ?? false;
    } else {
      //   Face comparison 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: () {
                  livenessDetection();
                },
                child: Text('Start Liveness'))
          ],
        ),
      ),
    );
  }
}