facerecognitionflutter

August 1, 2026 · View on GitHub

pub package platform

Offline face recognition and liveness detection Flutter plugin for Android and iOS. Built for FaceAISDK, it supports face enrollment, 1:1 face verification, liveness detection, and local face feature management.

FaceAISDK Flutter demo

Features

  • Offline face enrollment from SDK camera or Base64 image.
  • 1:1 face verification with action, color, and silent liveness detection.
  • Liveness-only detection for real-person checks.
  • Local face feature query, insert, delete, and face image export.
  • Built-in native UI plus direct Flutter API calls.

Silent liveness threshold (iOS/Android): 0.85–0.95. Actual performance varies with camera and lighting—adjust based on scenario

Platform Support

PlatformMinimum VersionCamera EnrollmentImage EnrollmentFace VerifyLiveness
AndroidminSdk 21YesYesYesYes
iOS15.5YesYesYesYes

Installation

flutter pub add face_recognition_flutter

Android

Add camera permission:

<uses-permission android:name="android.permission.CAMERA" />

Make sure minSdkVersion is at least 21.

iOS

Add camera usage text to Info.plist:

<key>NSCameraUsageDescription</key>
<string>FaceAISDK needs camera access for face enrollment and liveness verification.</string>

Make sure the iOS deployment target is at least 15.5.

Quick Start

import 'package:face_recognition_flutter/face_recognition_flutter.dart';

final result = await FaceRecognitionFlutter.faceVerify(
  faceId: 'user_001',
  threshold: 0.84,
  livenessType: 1,
  motionLivenessTypes: '1,2,3,4,5',
);

if (result.isSuccess) {
  print('Verified: ${result.similarity}');
}

Common APIs

// Enroll by SDK camera.
await FaceRecognitionFlutter.addFaceBySDKCamera(faceId: 'user_001');

// Enroll by Base64 image.
await FaceRecognitionFlutter.addFaceBySDKImage(
  faceId: 'user_001',
  imageBase64: 'data:image/jpeg;base64,...',
);

// Liveness only.
await FaceRecognitionFlutter.livenessVerify(livenessType: 2);

// Face feature management.
await FaceRecognitionFlutter.getFaceFeature('user_001');
await FaceRecognitionFlutter.insertFaceFeature(faceId: 'user_001', feature: '...');
await FaceRecognitionFlutter.deleteFaceFeature('user_001');

Run the Example

This is a Flutter plugin. Run the demo from the example app:

cd example
flutter run

If you run from the plugin root, specify the target:

flutter run -t example/lib/main.dart

Result Codes

CodeConstantMeaning
0DEFAULTInitial state; the flow has not started yet
1VERIFY_SUCCESS1:1 face verification passed; similarity is higher than the configured threshold
2VERIFY_FAILED1:1 face verification failed; similarity is lower than the configured threshold
3MOTION_LIVENESS_SUCCESSMotion liveness passed; the SDK may continue to the next step automatically
4MOTION_LIVENESS_TIMEOUTMotion liveness timed out
5NO_FACE_MULTIFace detection failed several times in a row
6NO_FACE_FEATURENo valid face feature was detected or extracted
7COLOR_LIVENESS_SUCCESSColor liveness passed
8COLOR_LIVENESS_FAILEDColor liveness failed
9COLOR_LIVENESS_LIGHT_TOO_HIGHColor liveness failed because ambient light is too bright
10ALL_LIVENESS_SUCCESSAll liveness steps passed, including motion and color liveness
11SILENT_LIVENESS_FAILEDSilent liveness failed
12NO_BASE_FACE_FEATURENo registered base face feature exists locally
13NOT_ALLOW_MULTI_FACESMultiple faces appeared in the camera frame

Troubleshooting

  • Target file "lib/main.dart" not found: run cd example && flutter run.
  • iOS cannot find Swift demo views: run cd example/ios && pod install.
  • Android Studio shows no devices while CLI works: restart adb with adb kill-server && adb start-server, then restart Android Studio.
  • iOS simulator arm64 warnings may come from transitive MLKit/TensorFlowLite dependencies; use a real iOS device when needed.

face_recognition_flutter 中文说明

适用于 Android 和 iOS 的 FaceAISDK 离线人脸识别 Flutter 插件,支持人脸录入、1:1 人脸核验、活体检测和本地人脸特征管理。

功能

  • 通过 SDK 相机或 Base64 图片录入人脸。

  • 支持动作、炫彩、静默活体检测。

  • 支持 1:1 人脸识别 + 活体检测。

  • 支持查询、同步、删除本地人脸特征值。

  • 支持原生内置 UI 和 Flutter API 直接调用。

    iOS Android 静默活体通过阈值范围0.85到0.95,注意实际表现和摄像头&环境有关

平台支持

平台最低版本相机录入图片录入人脸核验活体检测
AndroidminSdk 21支持支持支持支持
iOS15.5支持支持支持支持

安装

flutter pub add face_recognition_flutter

Android 添加相机权限:

<uses-permission android:name="android.permission.CAMERA" />

iOS 在 Info.plist 添加:

<key>NSCameraUsageDescription</key>
<string>FaceAISDK needs camera access for face enrollment and liveness verification.</string>

快速使用

import 'package:face_recognition_flutter/face_recognition_flutter.dart';

final result = await FaceRecognitionFlutter.faceVerify(
  faceId: 'user_001',
  threshold: 0.84,
  livenessType: 1,
  motionLivenessTypes: '1,2,3,4,5',
);

if (result.isSuccess) {
  print('核验成功: ${result.similarity}');
}

运行示例

cd example
flutter run

如果在插件根目录运行:

flutter run -t example/lib/main.dart

结果状态码

状态码常量名详细描述
0DEFAULT初始化状态,流程尚未开始
1VERIFY_SUCCESS1:1 人脸比对成功,相似度高于设置的阈值
2VERIFY_FAILED1:1 人脸比对失败,相似度低于设置的阈值
3MOTION_LIVENESS_SUCCESS动作活体检测成功,通常会自动进入后续流程
4MOTION_LIVENESS_TIMEOUT动作活体检测超时
5NO_FACE_MULTI连续多次未能成功检测到人脸
6NO_FACE_FEATURE未检测到或无法提取有效的人脸特征值
7COLOR_LIVENESS_SUCCESS炫彩活体检测通过
8COLOR_LIVENESS_FAILED炫彩活体检测失败
9COLOR_LIVENESS_LIGHT_TOO_HIGH炫彩活体检测失败,环境光线亮度过高
10ALL_LIVENESS_SUCCESS所有活体检测环节全部完成,包含动作与炫彩
11SILENT_LIVENESS_FAILED静默活体检测失败
12NO_BASE_FACE_FEATURE本地未注册或未录入基准人脸信息
13NOT_ALLOW_MULTI_FACES摄像头画面中出现多张人脸

常见问题

  • Target file "lib/main.dart" not found:请进入 example 目录运行。
  • iOS 找不到 Swift 示例页面:执行 cd example/ios && pod install
  • Android Studio 看不到设备:重启 adb 和 Android Studio。
  • iOS 模拟器依赖架构警告:建议使用真机验证。