π§ flutter_liveness_detection
flutter_liveness_detection is a powerful and easy-to-integrate Flutter plugin that enables real-time liveness detection using the deviceβs front camera.
This plugin validates the presence of a live human being by detecting natural facial movements such as:
- ποΈ Eye Blinking
- π Smiling
- π Head movement (left and right)
Ideal for applications that require face-based identity verification, such as KYC, biometric login, or attendance systems.
π Features
- β Detects facial movements to confirm user presence
- ποΈ Eye blink detection
- π Smile detection
- βοΈ Head movement detection (left & right)
- π₯ Front camera feed access
- π§ Real-time detection using optimized performance
- π± Supports both Android and iOS
- π οΈ Easy to integrate into any Flutter project
- π Ideal for security-focused use cases
π§ Getting Started
π¦ Installation
Add the package to your pubspec.yaml:
dependencies:
flutter_liveness_detection: ^0.0.6
π Permissions & Requirements
To use flutter_liveness_detection, ensure the following:
β Android Requirements:
- Minimum SDK version:
21 - Permissions Required:
Add these to your
AndroidManifest.xmlfile:
<uses-permission android:name="android.permission.CAMERA"/>
π οΈ Quick Usage
To trigger liveness detection, just call the widget inside a button press:
ElevatedButton(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(20),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
foregroundColor: Colors.black,
backgroundColor: Colors.blueAccent,
),
onPressed: () async {
// Step 1: Get the list of available cameras on the device
final List<CameraDescription> cameras = await availableCameras();
// Step 2: Proceed only if there's at least one camera (front camera)
if (cameras.isNotEmpty) {
// π§ You can set any 2 or more actions from below to verify the user is real.
// The user will be asked to perform these actions for verification.
List<Moment> challengeActions = [
Moment.smile, // π Ask user to smile
Moment.eyeblink, // ποΈ Ask user to blink
Moment.leftPose, // π Turn head left
Moment.rightPose, // π Turn head right
];
// Step 3: Start the liveness detection screen with defined actions, Call this widget 'FlutterLivenessDetection'
final XFile? result = await Navigator.push(context,
MaterialPageRoute(
builder: (context) => FlutterLivenessDetection(moments: challengeActions),
),
);
// Step 4: If selfie is returned, that means verification passed
if (result != null) {
setState(() {
imageFile = File(result.path);
});
// Step 5: You can save/upload the image. Show success message.
print('Selfie path: ${result.path}');
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Verification Successful!')),
);
}
} else {
// β No camera found on device
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Camera not active!')),
);
}
},
child: const Text('Verify Now', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20)),
),