Flutter Identity Comparison SDK
A Flutter SDK for identity verification using liveness checks and ID verification. This SDK provides a seamless integration for applications requiring identity verification across multiple platforms (Android, iOS, and Web).
Table of Contents
Features
- Liveness Detection: Verify that the user is a real person and not a photo or video.
- Identity Verification: Compare the user's face with their ID document.
- Cross-Platform Support: Works on Android, iOS, and Web platforms.
- Customizable UI: Easily customize the appearance to match your app's design.
- Secure: All processing is done through secure API endpoints.
Installation
Add the Flutter Identity Comparison SDK to your pubspec.yaml
file:
dependencies:
flutter_identity_comparison_sdk:
git:
url: https://github.com/yourusername/flutter_identity_comparison_sdk.git
ref: main
Or, if you're using a local copy:
dependencies:
flutter_identity_comparison_sdk:
path: ../flutter_identity_comparison_sdk
Then run:
flutter pub get
Dependencies
This SDK relies on the following packages:
camera: ^0.10.6
google_mlkit_face_detection: ^0.3.0
google_mlkit_commons: ^0.2.0
http: ^0.13.5
Usage
Basic Implementation
- Import the package:
import 'package:flutter_identity_comparison_sdk/flutter_identity_comparison_sdk.dart';
- Add the
IdentityComparisonWidget
to your app:
class _MyAppState extends State<MyApp> {
void _startIdentityVerification() {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => Scaffold(
appBar: AppBar(
title: const Text('Identity Verification'),
),
body: IdentityComparisonWidget(
name: 'Your App Name',
apiUrl: 'https://your-api-endpoint.com',
apiKey: 'your-api-key',
onIdentityComparisonResult: (result) {
print('Identity comparison result: ${result.isMatch}');
// Handle the result
},
),
),
),
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('My App'),
),
body: Center(
child: ElevatedButton(
onPressed: _startIdentityVerification,
child: const Text('Start Identity Verification'),
),
),
),
);
}
}
Advanced Configuration
The IdentityComparisonWidget
accepts several parameters for customization:
IdentityComparisonWidget(
name: 'Your App Name',
apiUrl: 'https://your-api-endpoint.com',
apiKey: 'your-api-key',
onIdentityComparisonResult: (result) {
// Handle the result
},
primaryColor: Colors.blue,
secondaryColor: Colors.white,
fontFamily: 'Roboto',
idTypes: const ['National ID', 'Passport', 'Driver\'s License'],
instructions: 'Please position your face within the frame for verification.',
showLogo: true,
logoPath: 'assets/logo.png',
)
Platform-Specific Considerations
Android
Permissions
Add the following permissions to your AndroidManifest.xml
file:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
Troubleshooting Android Issues
-
Camera Not Working: Ensure you have requested camera permissions at runtime.
-
Face Detection Issues: The SDK uses Google ML Kit for face detection. Make sure your device supports Google Play Services.
-
Gradle Build Errors: If you encounter duplicate class errors, check for conflicting dependencies in your app's
build.gradle
file. You may need to exclude certain transitive dependencies:
implementation('com.google.android.gms:play-services-mlkit-face-detection:16.2.0') {
exclude group: 'com.google.android.gms', module: 'play-services-base'
}
- NDK Version Compatibility: Ensure your Android NDK version is compatible with the ML Kit dependencies. We recommend using NDK version 21.4.7075529 or later.
iOS
Permissions
Add the following to your Info.plist
file:
<key>NSCameraUsageDescription</key>
<string>This app needs camera access for identity verification</string>
Troubleshooting iOS Issues
-
Camera Access: If the camera doesn't initialize, check that you've properly set up the
NSCameraUsageDescription
in yourInfo.plist
. -
Build Errors: If you encounter build errors related to Pods, try:
cd ios pod deintegrate pod install
-
Face Detection Performance: On older iOS devices, face detection might be slower. Consider adding a loading indicator during processing.
Web
Browser Compatibility
The SDK supports modern browsers including:
- Chrome (recommended)
- Firefox
- Safari
- Edge
Web-Specific Limitations
-
Camera Access: The web version uses the browser's
getUserMedia
API for camera access. This requires:- The site to be served over HTTPS (except for localhost)
- User permission to access the camera
-
Face Detection: On web platforms, face detection is simplified compared to mobile platforms:
- The SDK automatically enables the capture button without requiring face detection
- Users should ensure their face is clearly visible before capturing
-
Performance: Face detection and processing may be slower on web platforms compared to native mobile apps.
-
Browser Storage: The SDK uses browser storage for temporary data. If you encounter "QUOTA_BYTES exceeded" errors, consider:
- Reducing the size of stored data
- Clearing browser storage before initializing the SDK
Troubleshooting Web Issues
-
Camera Not Starting: If the camera doesn't start on web:
- Check that your site is served over HTTPS
- Ensure the user has granted camera permissions
- Verify that the browser supports
getUserMedia
-
"Platform._operatingSystem" Error: This error occurs when using platform-specific code on web. The SDK handles this internally by using the
PlatformHelper
class. -
Face Detection Errors: If you encounter errors related to face detection on web:
- The SDK automatically disables ML Kit face detection on web
- Users can still capture photos without face detection
API Reference
IdentityComparisonWidget
The main widget for identity verification.
Parameter | Type | Description |
---|---|---|
name |
String |
Your app name |
apiUrl |
String |
The API endpoint for verification |
apiKey |
String |
Your API key |
onIdentityComparisonResult |
Function(IdentityComparisonResponse) |
Callback for the verification result |
primaryColor |
Color? |
Primary color for UI elements |
secondaryColor |
Color? |
Secondary color for UI elements |
fontFamily |
String? |
Font family for text |
idTypes |
List<String>? |
List of ID types to choose from |
instructions |
String? |
Custom instructions for the user |
showLogo |
bool? |
Whether to show a logo |
logoPath |
String? |
Path to your logo asset |
IdentityComparisonResponse
The result of the identity verification process.
Property | Type | Description |
---|---|---|
isMatch |
bool |
Whether the face matches the ID |
confidence |
double |
Confidence score (0-1) |
message |
String? |
Additional information |
errorCode |
String? |
Error code if applicable |
timestamp |
DateTime |
When the verification was performed |
Troubleshooting
Common Issues
-
Camera Initialization Failed
- Check camera permissions
- Ensure no other app is using the camera
- Restart the app
-
Face Detection Not Working
- Ensure adequate lighting
- Position face clearly in the frame
- Check if Google Play Services is available (Android)
-
API Connection Errors
- Verify internet connectivity
- Check API URL and key
- Ensure the API endpoint is accessible
-
Platform-Specific Errors
- See the platform-specific sections above
Logging
Enable debug logging for troubleshooting:
FlutterIdentityComparisonSdk.enableDebugLogs(true);
License
This project is licensed under the MIT License - see the LICENSE file for details.