FaceDetectorScreen class

The main widget for real-time face liveness detection.

Displays a camera preview with an animated dotted progress ring and guides the user through a configurable sequence of Rulesets challenges. When all challenges have been completed, onValidationDone is called with the active CameraController so the caller can capture a photo.

Minimal usage

FaceDetectorScreen(
  onRulesetCompleted: (ruleset) => debugPrint('Done: $ruleset'),
  onValidationDone: (controller) {
    return ElevatedButton(
      onPressed: () async => await controller?.takePicture(),
      child: const Text('Capture'),
    );
  },
  child: ({required state, required countdown, required hasFace}) {
    return Text(hasFace ? 'Hold still… $countdown' : 'Show your face');
  },
)
Inheritance

Constructors

FaceDetectorScreen({Key? key, required void onRulesetCompleted(Rulesets ruleset)?, required Widget onValidationDone(CameraController? controller), List<Rulesets> ruleset = const [Rulesets.smiling, Rulesets.blink, Rulesets.toRight, Rulesets.toLeft, Rulesets.tiltUp, Rulesets.tiltDown, Rulesets.normal], required Widget child({required int countdown, required bool hasFace, required Rulesets state}), Color progressColor = Colors.green, Color activeProgressColor = Colors.red, int totalDots = 60, double dotRadius = 3, dynamic onSuccessValidation(bool validated)?, Color? backgroundColor = Colors.white, EdgeInsetsGeometry? contextPadding, Size cameraSize = const Size(200, 200), int pauseDurationInSeconds = 5, void onController(CameraController controller)?})
const

Properties

activeProgressColor Color
Color of dots that represent completed progress in the ring.
final
backgroundColor Color?
Background color of the widget. Defaults to Colors.white.
final
cameraSize Size
Size of the circular camera preview. Defaults to 200×200.
final
child Widget Function({required int countdown, required bool hasFace, required Rulesets state})
Builder for the overlay widget shown during liveness challenges.
final
contextPadding EdgeInsetsGeometry?
Padding around the content column.
final
dotRadius double
Radius of each dot in logical pixels. Defaults to 3.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onController → void Function(CameraController controller)?
final
onRulesetCompleted → void Function(Rulesets ruleset)?
Called each time a single ruleset challenge is completed.
final
onSuccessValidation → dynamic Function(bool validated)?
Called with true when all validations pass, false otherwise.
final
onValidationDone Widget Function(CameraController? controller)
Builder for the widget shown after all challenges pass.
final
pauseDurationInSeconds int
Seconds to pause between ruleset steps. Defaults to 5.
final
progressColor Color
Color of dots that represent remaining progress in the ring.
final
ruleset List<Rulesets>
Ordered list of liveness challenges to perform. Must not be empty.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
totalDots int
Total number of dots in the progress ring. Defaults to 60.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<FaceDetectorScreen>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

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