FaceDetectionController class

Controller that manages camera initialization, face detection, and optional face verification.

// Basic usage — any face unlocks
final controller = FaceDetectionController()..initializeCamera();

// With verification — only enrolled faces unlock
final controller = FaceDetectionController(
  verificationProvider: LocalFaceVerificationProvider(),
)..initializeCamera();
Inheritance

Constructors

FaceDetectionController({void onFaceSnapshot(List<Face>)?, CameraController? cameraController, CameraLensDirection camDirection = CameraLensDirection.front, ResolutionPreset resolution = ResolutionPreset.low, Duration initTimeout = const Duration(seconds: 10), Duration detectionInterval = const Duration(milliseconds: 300), Duration lockDelay = const Duration(milliseconds: 500), Duration unlockDelay = Duration.zero, double minFaceSize = 0.15, FaceVerificationProvider? verificationProvider, bool enableLiveness = true, int? maxFaces, MultiFacePolicy multiFacePolicy = MultiFacePolicy.lockIfMultiple, bool batteryAwareMode = false, int batteryThreshold = 20, Duration lowBatteryDetectionInterval = const Duration(milliseconds: 1000), Battery? battery})

Properties

batteryAwareMode bool
Whether to reduce detection frequency when battery is low. Defaults to false (opt-in).
final
batteryThreshold int
Battery level (0–100) below which low-battery detection interval applies. Only used when batteryAwareMode is true. Defaults to 20.
final
camDirection → CameraLensDirection
Camera lens direction. Defaults to front camera.
final
cameraController → CameraController?
Use an existing camera controller for fine-grained camera control.
final
detectionInterval Duration
Minimum interval between detection runs. Frames arriving faster than this are skipped. Defaults to 300ms (~3 detections/sec).
final
enableLiveness bool
Whether to run liveness checks during verification. Only used when verificationProvider is set. Defaults to true.
final
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
initTimeout Duration
Timeout for camera initialization. Defaults to 10 seconds.
final
lockDelay Duration
Delay before locking after the last face disappears. Prevents flicker when a face is momentarily lost. Defaults to 500ms.
final
lowBatteryDetectionInterval Duration
Detection interval used when battery is below batteryThreshold. Only used when batteryAwareMode is true. Defaults to 1000ms.
final
maxFaces int?
Maximum number of faces allowed before locking. When null (default), any number of faces is accepted.
final
minFaceSize double
Minimum face size relative to the image (0.0–1.0). Smaller values detect faces further away. Defaults to 0.15.
final
multiFacePolicy MultiFacePolicy
Policy for handling multiple detected faces. Only applies when maxFaces is set. Defaults to MultiFacePolicy.lockIfMultiple.
final
onFaceSnapshot → void Function(List<Face>)?
Callback invoked with the list of detected faces each time a face is found.
final
resolution → ResolutionPreset
Camera resolution preset. Defaults to ResolutionPreset.low for optimal detection performance and battery usage.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state FaceDetectionState
The current state of face detection.
no setter
stream Stream<FaceDetectionState>
A broadcast stream of state changes.
no setter
unlockDelay Duration
Delay before unlocking after a face first appears. Prevents flicker from brief false positives. Defaults to 0ms (instant).
final
verificationProvider FaceVerificationProvider?
Optional face verification provider. When set, detected faces are verified against enrolled templates before unlocking.
final

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
close() Future<void>
Release all resources — camera, detector, stream, listeners.
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
inherited
initializeCamera() → void
Initialize the camera and start the face detection image stream.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
pause() → void
Pause face detection (e.g. when the app is backgrounded).
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
resume() → void
Resume face detection after a pause.
simulateFaceDetected() → void
Simulate a face being detected. Only for use in tests.
simulateNoFace() → void
Simulate no face being detected. Only for use in tests.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited