When to use Flutter Face Api
Flutter Face Api brings the power of Regula's facial recognition engine to your Flutter applications with a thin, idiomatic Dart layer. The package abstracts the native iOS and Android SDKs, exposing a simple asynchronous API that lets you capture a face, extract its biometric template, and compare it against another template in real time.
All processing happens on the device, which means no network latency, no privacy concerns, and compliance with regulations that forbid sending raw facial data to the cloud.\n\nThe library shines in scenarios where you need instant verification – think check‑in kiosks, secure banking apps, or attendance systems that must work offline. Because the heavy lifting is performed by Regula's native code, you get high‑accuracy matching without having to train or host a machine‑learning model yourself.
The API is deliberately minimal: you initialize the SDK with your license key, request camera permissions, capture a face image, and then call `compareFaces` to receive a similarity score. This workflow fits neatly into any Flutter architecture, whether you are using Provider, Bloc, Riverpod, or a plain StatefulWidget.\n\nIntegrating Flutter Face Api into an existing codebase is straightforward.
After adding the dependency, you register the SDK in your `main` function, optionally configuring logging or custom detection thresholds. The package supplies a ready‑made widget that handles camera preview, focus, and image capture, but you are also free to plug in your own camera implementation if you already use a different package.
The result of a comparison is a numeric confidence value (0‑100) that you can map to your own business rules – for example, accepting a match above 85% for high‑security actions and prompting a fallback for lower scores.\n\nWhen moving to production, keep a few cautions in mind. First, the Regula SDK requires a valid license key that is tied to your app bundle identifier (iOS) or package name (Android); distributing the key publicly can lead to abuse, so store it securely, preferably in native code or encrypted assets.
Second, because the algorithm runs on the device CPU/GPU, performance varies across hardware; testing on low‑end Android devices is essential to ensure acceptable frame rates and battery consumption. Third, be aware of platform‑specific permission flows – iOS needs a usage description in `Info.plist`, while Android requires runtime camera permission and, for Android 12+, the `android:exported` flag for the SDK's activities.
Finally, always inform users why you are capturing facial data and obtain explicit consent to stay compliant with privacy regulations such as GDPR or CCPA.\n\nFor beginners, the package offers a quick‑start tutorial that walks you through a three‑step process: (1) add the dependency, (2) initialize the SDK with a test key, and (3) run the sample `FaceComparisonScreen` widget. The sample demonstrates error handling for permission denials, shows how to display the similarity score, and includes a fallback UI for manual verification.
Because the API is asynchronous and returns `Future<double>`, it integrates cleanly with `async/await` patterns and can be combined with state‑management solutions to trigger UI updates only when a result is ready. Whether you are building a prototype or a production‑grade biometric flow, Flutter Face Api gives you a reliable, on‑device solution that reduces latency, protects user privacy, and leverages the robustness of Regula's proven facial recognition technology.
Pros
- on‑device processing preserves privacy
- high accuracy thanks to Regula engine
- simple async Dart API
- works offline
- supports both Android and iOS
Watch outs
- requires native license key management
- no web or desktop support yet
- performance varies on low‑end devices
- adds native SDK size to app bundle
Setup notes
Add the package to your project with the command: ``` flutter pub add flutter_face_api ``` Then run `flutter pub get`. On iOS, add `NSCameraUsageDescription` to `Info.plist`. On Android, ensure `android.permission.CAMERA` is declared in `AndroidManifest.xml` and request runtime permission. Finally, initialize the SDK early in `main()` using your Regula license key: ```dart await FlutterFaceApi.initialize('YOUR_LICENSE_KEY'); ```
Supports Android API 21+ and iOS 11+. Requires camera hardware and appropriate permissions. Works with both portrait and landscape orientations. No web or desktop support at this time.
```dart
import 'package:flutter/material.dart';
import 'package:flutter_face_api/flutter_face_api.dart';
class FaceComparisonScreen extends StatefulWidget {
const FaceComparisonScreen({Key? key}) : super(key: key);
@override
State<FaceComparisonScreen> createState() => _FaceComparisonScreenState();
}
class _FaceComparisonScreenState extends State<FaceComparisonScreen> {
double? _score;
String? _error;
Future<void> _compare() async {
try {
final template1 = await FlutterFaceApi.captureAndExtract();
final template2 = await FlutterFaceApi.captureAndExtract();
final result = await FlutterFaceApi.compareFaces(template1, template2);
setState(() => _score = result);
} catch (e) {
setState(() => _error = e.toString());
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Face Comparison')),
body: Center(
child: _error != null
? Text('Error: $_error', style: const TextStyle(color: Colors.red))
: _score != null
? Text('Similarity: ${_score!.toStringAsFixed(1)}%')
: const Text('Press the button to start'),
),
floatingActionButton: FloatingActionButton(
onPressed: _compare,
child: const Icon(Icons.camera),
),
);
}
}
```