human_security 0.2.1 copy "human_security: ^0.2.1" to clipboard
human_security: ^0.2.1 copied to clipboard

On-device face liveness verification with ML Kit active challenges, TFLite anti-spoofing, and optional face identity matching.

pub package Android iOS

human_security #

Flutter package for on-device face liveness on Android and iOS.

  • Active liveness — ML Kit challenges (blink, smile, head turns)
  • Passive anti-spoof — bundled TFLite model
  • Face match (optional) — compare live capture to a reference photo

All processing runs on the device. No server is required for liveness or face matching.


Install #

dependencies:
  human_security: ^0.2.1
flutter pub get

Android configuration #

1. Permissions — android/app/src/main/AndroidManifest.xml #

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />

INTERNET is only needed if you load a reference image from a URL.

2. Gradle — android/app/build.gradle.kts #

android {
    defaultConfig {
        minSdk = 24
    }

    androidResources {
        noCompress += "tflite"
    }
}

configurations.all {
    resolutionStrategy {
        force("org.tensorflow:tensorflow-lite:2.16.1")
        force("org.tensorflow:tensorflow-lite-gpu:2.16.1")
        force("org.tensorflow:tensorflow-lite-api:2.16.1")
    }
}

3. Runtime #

Request camera permission before opening FaceLivenessDetector (e.g. permission_handler).


iOS configuration #

1. Deployment target — ios/Podfile #

platform :ios, '15.5'

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.5'
    end
  end
end

Then run:

cd ios && pod install && cd ..

2. Privacy — ios/Runner/Info.plist #

<key>NSCameraUsageDescription</key>
<string>Camera access is required for face liveness verification.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Photo library access is required to pick a reference face image.</string>

NSPhotoLibraryUsageDescription is only needed if your app picks a reference image from the gallery.


Usage #

Liveness only #

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:human_security/human_security.dart';

class LivenessPage extends StatelessWidget {
  const LivenessPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: FaceLivenessDetector(
        onSuccess: (File image, FaceMatchReport? report) {
          // `image` — captured live selfie
          // `report` — liveness scores (if available)
        },
        onFailure: (String reason) {
          // Spoof, timeout, or setup error
        },
      ),
    );
  }
}

Liveness + face match #

FaceLivenessDetector(
  referenceImage: ReferenceImageSource.file(referenceFile),
  // ReferenceImageSource.url('https://example.com/photo.jpg')
  // ReferenceImageSource.bytes(imageBytes)
  matchThreshold: 0.75,
  onSuccess: (image, report) {
    if (report?.isVerified ?? false) {
      // Live face matches reference
    }
  },
  onFailure: (reason) {},
)

Common options #

Parameter Default Description
challengeCount 2 Number of active challenges
enablePassiveLiveness true TFLite anti-spoof on/off
matchThreshold 0.75 Face similarity threshold
showCameraFlipButton true Front/back camera toggle
backgroundColor Colors.black Screen background
progressColor Colors.greenAccent Progress bar color

Active-only mode (no TFLite):

FaceLivenessDetector(
  enablePassiveLiveness: false,
  onSuccess: (image, report) {},
  onFailure: (reason) {},
)

Example app #

cd example
flutter pub get
cd ios && pod install && cd ..
flutter run

The example demonstrates full liveness, active-only mode, and optional reference-image matching.


2
likes
160
points
154
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

On-device face liveness verification with ML Kit active challenges, TFLite anti-spoofing, and optional face identity matching.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

camera, flutter, google_mlkit_face_detection, http, image, path, path_provider, rxdart, tflite_flutter

More

Packages that depend on human_security