face_verification 0.0.6
face_verification: ^0.0.6 copied to clipboard
On-device face verification using FaceNet-style embeddings with an offline TFLite model for Flutter (Android/iOS).
Face Verification β Simple Face Recognition for Flutter #
Add secure face recognition to your Flutter app in minutes. This plugin lets you register users' faces and verify their identity later β all processing happens on-device for privacy and works offline.
Perfect for attendance systems, secure login, user verification, and access control apps.
π What You Can Do #
- Register faces: Take a photo and save someone's face profile
- Verify identity: Check if a new photo matches any registered person
- Check registration status: Verify if someone is already registered
- Works offline: No internet required, all processing on-device
- Privacy-first: Face data never leaves the device
- Simple API: Just a few main functions to get started
π± Quick Demo #
// 1. Initialize (do this once when your app starts)
await FaceVerification.instance.init();
// 2. Register someone's face
await FaceVerification.instance.registerFromImagePath(
id: 'john_doe',
imagePath: '/path/to/johns_photo.jpg',
imageId: 'profile_pic',
);
// 3. Later, verify if a new photo matches John
final matchId = await FaceVerification.instance.verifyFromImagePath(
imagePath: '/path/to/new_photo.jpg',
threshold: 0.70, // How strict the match should be (0-1)
);
if (matchId == 'john_doe') {
print('Welcome back, John!');
} else {
print('Face not recognized');
}
π¦ Installation #
Add to your pubspec.yaml:
dependencies:
face_verification: ^0.0.6
Run:
flutter pub get
That's it! The face recognition model is included automatically.
π οΈ Platform Setup #
iOS Requirements #
- iOS 15.5 or newer
- Xcode 15.3.0+
Add this to your ios/Podfile:
platform :ios, '15.5'
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=*]"] = "armv7"
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.5'
end
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.5'
end
end
end
Android Requirements #
Update your android/app/build.gradle:
android {
compileSdkVersion 35
defaultConfig {
minSdkVersion 21
targetSdkVersion 35
}
}
π― Complete Usage Guide #
Step 1: Initialize the Plugin #
Do this once when your app starts, typically in main() or your first screen:
import 'package:face_verification/face_verification.dart';
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
_initializeFaceVerification();
}
Future<void> _initializeFaceVerification() async {
try {
await FaceVerification.instance.init();
print('Face verification ready!');
} catch (e) {
print('Failed to initialize: $e');
}
}
}
Step 2: Register a Person's Face #
When someone needs to register (like employee onboarding or user signup):
Future<void> registerNewPerson(String personId, String photoPath) async {
try {
final result = await FaceVerification.instance.registerFromImagePath(
id: personId, // Unique ID like 'employee_123' or 'user_john'
imagePath: photoPath, // Path to their photo
imageId: 'main_photo', // Required: label for this photo
);
print('β
Successfully registered: $result');
// Show success message to user
} catch (e) {
print('β Registration failed: $e');
// Handle errors (no face detected, multiple faces, etc.)
}
}
Step 3: Verify Someone's Identity #
When someone tries to log in or access something:
Future<void> verifyPerson(String photoPath) async {
try {
final matchId = await FaceVerification.instance.verifyFromImagePath(
imagePath: photoPath,
threshold: 0.70, // 0.70 = good balance, 0.80 = stricter, 0.60 = more lenient
);
if (matchId != null) {
print('β
Welcome back, $matchId!');
// Grant access or log them in
} else {
print('β Face not recognized');
// Show error or fallback to password
}
} catch (e) {
print('β Verification failed: $e');
}
}
Step 4: Check Specific Person (Optional) #
If you want to verify against one specific person instead of everyone:
Future<void> verifySpecificPerson(String photoPath, String expectedPersonId) async {
final matchId = await FaceVerification.instance.verifyFromImagePath(
imagePath: photoPath,
threshold: 0.70,
staffId: expectedPersonId, // Only check against this person
);
if (matchId == expectedPersonId) {
print('β
Identity confirmed for $expectedPersonId');
} else {
print('β Not a match for $expectedPersonId');
}
}
π§ Registration Status & Management Functions #
Check Registration Status #
Before registering or to prevent duplicates:
// Check if someone is already registered by ID
final isRegistered = await FaceVerification.instance.isFaceRegistered('john_doe');
if (isRegistered) {
print('User john_doe is already registered');
} else {
print('User john_doe is not registered yet');
}
// Check if specific ID + imageId combination exists
final hasSpecificImage = await FaceVerification.instance.isFaceRegisteredWithImageId(
'john_doe',
'profile_pic'
);
if (hasSpecificImage) {
print('Exact match found - same person with same image');
}
Use cases for registration checks:
- Prevent duplicate registrations
- Show appropriate UI (register vs re-register)
- Validate before allowing re-registration
- Check if user needs to register first
Other Management Functions #
// List all registered people
final records = await FaceVerification.instance.listRegisteredAsync();
print('${records.length} people registered');
// Remove someone's registration
await FaceVerification.instance.deleteRecord('employee_123');
// Clean up when app closes (optional)
await FaceVerification.instance.dispose();
βοΈ Understanding the Threshold #
The threshold parameter controls how strict face matching is:
- 0.60: More lenient (might accept similar-looking people)
- 0.70: Balanced (recommended for most apps)
- 0.80: Strict (reduces false positives, might reject valid matches)
- 0.90: Very strict (use for high-security applications)
πΈ Tips for Best Results #
Good photos:
- Clear, front-facing face
- Good lighting
- No sunglasses or masks
- Single person in frame
Avoid:
- Blurry images
- Multiple faces
- Very dark photos
- Extreme angles
π¨ Common Issues & Solutions #
"No face detected"
- Make sure photo has a clear, visible face
- Check lighting and image quality
"Multiple faces detected"
- Crop photo to show only one person
- Use photos with single subjects
"ID already exists" error
- Check if user is already registered using
isFaceRegistered() - Use different imageId for re-registration
- Delete existing record first if needed
iOS build errors
- Make sure you excluded armv7 architecture as shown above
- Test on physical device, not simulator
Low accuracy
- Adjust threshold value
- Use higher quality photos
- Re-register with better photos
π¨ Custom Model (Advanced) #
Want to use your own face recognition model?
await FaceVerification.instance.init(
modelAsset: 'assets/models/my_custom_model.tflite',
numThreads: 4,
);
Add the model to your pubspec.yaml:
flutter:
assets:
- assets/models/my_custom_model.tflite
π± Example App #
Check out the complete working example in the example/ folder:
cd example
flutter run
π Need Help? #
Having issues? Please open an issue with:
- Your platform (iOS/Android) and versions
- Device model
- Error messages
- Sample code that isn't working
π License #
MIT License - see LICENSE file for details.
β Found this helpful? Please star the repo and leave a review on pub.flutter-io.cn!