face_liveness_verifier A Flutter plugin for face liveness detection with randomized challenges to verify real human presence through facial movements. Features
Real-time Face Detection: Uses Google ML Kit to detect faces and facial features. Randomized Challenges: Prompts users to perform random actions (blink, look left/right/up/down, smile) to verify liveness. Customizable: Supports custom labels, thresholds, and UI options. Cross-platform: Works on Android and iOS. Image Capture: Returns the path of the captured image upon successful verification.
Installation Add the following to your pubspec.yaml: dependencies: face_liveness_verifier: ^1.0.0
Run: flutter pub get
Permissions Android Add to android/app/src/main/AndroidManifest.xml:
iOS Add to ios/Runner/Info.plist:
Usage import 'package:face_liveness_verifier/face_liveness_verifier.dart'; import 'package:flutter/material.dart';
void main() { runApp(MyApp()); }
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: Text('Liveness Detection')), body: Center( child: ElevatedButton( onPressed: () async { final path = await FaceLivenessVerifierPlugin.instance.startLivenessDetection( context: context, config: LivenessConfig( isEnableMaxBrightness: true, durationLivenessVerify: 60, showDurationUiText: false, startWithInfoScreen: false, customLabels: { LivenessChallenge.blink: '👁️ Parpadea', LivenessChallenge.lookLeft: '⬅️ Izquierda', LivenessChallenge.lookRight: '➡️ Derecha', LivenessChallenge.lookUp: '⬆️ Arriba', LivenessChallenge.lookDown: '⬇️ Abajo', LivenessChallenge.smile: '😀 Sonríe', }, ), isEnableSnackBar: true, shuffleChallenges: true, isDarkMode: false, showCurrentChallenge: true, ); print('Captured image path: $path'); }, child: Text('Start Liveness Detection'), ), ), ), ); } }
Configuration Options
isEnableMaxBrightness: Set to true to maximize screen brightness during detection. durationLivenessVerify: Time limit (in seconds) for completing challenges. showDurationUiText: Show a countdown timer in the UI. startWithInfoScreen: Show an introductory screen before detection. customLabels: Customize challenge instructions. thresholds: Adjust detection thresholds for each challenge. isEnableSnackBar: Show feedback via SnackBar. shuffleChallenges: Randomize the order of challenges. isDarkMode: Use dark mode for the UI. showCurrentChallenge: Display the current challenge instruction.
Dependencies
camera: ^0.11.2 google_mlkit_face_detection: ^0.13.1 collection: ^1.18.0 screen_brightness: ^2.1.2 image: ^4.0.15 path_provider: ^2.1.3
Contributing Contributions are welcome! Please submit a pull request or open an issue on GitHub. License MIT License