SprintLiveness
A Flutter plugin for face liveness detection that fully supports Android and iOS platforms, with WebView support for other platforms.
Features
- Real-time Face Detection: Uses ML Kit on Android and native Vision Framework on iOS.
- Liveness Challenges: Randomized actions (Smile, Blink, Turn Left/Right, Tilt Up/Down) to ensure the user is live.
- Cross-platform: Support for Android and iOS, with a fallback WebView implementation for Web and Desktop.
- Easy Integration: Simple API to start liveness checks and get results.
- Customizable UI: Built-in UI with progress indicators and real-time instructions.
Installation
Add this to your package's pubspec.yaml file:
dependencies:
sprintliveness: ^0.1.0
Then run:
flutter pub get
Usage
First, import the package:
import 'package:sprintliveness/sprintliveness.dart';
import 'package:sprintliveness/model/liveness_response.dart';
Basic Usage
final _sprintlivenessPlugin = Sprintliveness();
Future<void> _startLivenessCheck(BuildContext context) async {
try {
final LivenessResult result = await _sprintlivenessPlugin.startLivenessCheck(context);
if (result.isSuccess) {
// Liveness check was successful.
// The `result.image` variable holds the Base64 encoded image string.
print('Liveness check passed: ${result.image}');
} else {
// Liveness check failed.
final exception = result.exception!;
print('Liveness check failed: ${exception.message} (${exception.code})');
}
} catch (e) {
print('An error occurred: $e');
}
}
Platform Requirements
Android
- Minimum SDK: 21 (Android 5.0)
- Camera permission required.
- Google Play Services (automatically handled).
Add these permissions to your android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
iOS
- Minimum iOS version: 15.5
- Camera permission required.
Add these permissions to your ios/Runner/Info.plist:
<key>NSCameraUsageDescription</key>
<string>This app needs camera access for face liveness detection</string>
API Reference
Sprintliveness
The main class to interact with the plugin.
startLivenessCheck(BuildContext context): Opens the liveness detection UI and returns aLivenessResult.
LivenessResult
The result object returned after a liveness check.
isSuccess: Boolean indicating if the check passed.image: Base64 encoded string of the captured face image (on success).exception:LivenessExceptioncontaining error details (on failure).
LivenessErrorCode
userCancelled: User closed the screen manually.challengeTimedOut: User took too long to complete an action.cameraPermissionDenied: Camera access was not granted.captureError: Failed to capture the final image.lowLight: Environment is too dark.
License
This project is licensed under the MIT License.
Support
For support and questions, please visit our homepage.
Libraries
- component/accent_painter
- component/badge
- component/circular_liveness_viewport
- component/liveness_action
- component/liveness_state
- component/ring_painter
- liveness_screen
- model/liveness_response
- services/face_detector_service
- services/face_detector_service_factory
- services/mobile_face_detector_service
- services/web_face_detector_service
- sprintliveness
- sprintliveness_method_channel
- sprintliveness_platform_interface
- sprintliveness_web
- webview_liveness_screen