sprintliveness 0.0.4
sprintliveness: ^0.0.4 copied to clipboard
Flutter plugin for face liveness detection. Fully supports Android && Ios platform.
SprintLiveness #
A Flutter plugin for face liveness detection that fully supports Android and iOS platforms.
Features #
- Face liveness detection using ML Kit
- Camera integration for real-time face detection
- Cross-platform support (Android & iOS)
- Easy-to-use API
- Permission handling
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
sprintliveness: ^0.0.3
Then run:
flutter pub get
Usage #
First, import the package:
import 'package:sprintliveness/sprintliveness.dart';
Basic Usage #
import 'package:flutter/material.dart';
import 'package:sprintliveness/sprintliveness.dart';
class LivenessCheckScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Liveness Check')),
body: SprintLivenessScreen(
onLivenessDetected: (result) {
print('Liveness result: ${result.isLive}');
// Handle liveness result
},
onError: (error) {
print('Error: $error');
// Handle errors
},
),
);
}
}
Advanced Usage #
class AdvancedLivenessScreen extends StatefulWidget {
@override
_AdvancedLivenessScreenState createState() => _AdvancedLivenessScreenState();
}
class _AdvancedLivenessScreenState extends State<AdvancedLivenessScreen> {
final SprintLivenessController _controller = SprintLivenessController();
@override
Widget build(BuildContext context) {
return SprintLivenessScreen(
controller: _controller,
onLivenessDetected: (result) {
if (result.isLive) {
// Proceed with authentication
Navigator.pushReplacementNamed(context, '/success');
} else {
// Show error message
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Liveness check failed')),
);
}
},
onError: (error) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error: $error')),
);
},
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
}
Platform Requirements #
Android #
- Minimum SDK: 21 (Android 5.0)
- Camera permission required
- Play Services for ML Kit
iOS #
- Minimum iOS version: 11.0
- Camera permission required
- Front camera access
Permissions #
Android #
Add these permissions to your android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
iOS #
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 #
SprintLivenessScreen #
A widget that provides the complete liveness detection UI.
Properties:
onLivenessDetected: Callback when liveness is detectedonError: Callback when an error occurscontroller: Optional controller for advanced control
LivenessResult #
Contains the result of the liveness check.
Properties:
isLive: Boolean indicating if face is liveconfidence: Confidence score (0.0 to 1.0)timestamp: Timestamp of the detection
Troubleshooting #
Common Issues #
- Camera not working: Ensure camera permissions are granted
- ML Kit errors: Check if Google Play Services is updated
- Performance issues: Use appropriate camera resolution
Error Codes #
CAMERA_PERMISSION_DENIED: Camera permission not grantedMLKIT_NOT_AVAILABLE: ML Kit is not available on deviceFACE_NOT_DETECTED: No face detected in camera view
Contributing #
Contributions are welcome! Please feel free to submit a Pull Request.
License #
This project is licensed under the MIT License - see the LICENSE file for details.
Support #
For support and questions, please visit our homepage.