facelivenessdetection 1.1.15
facelivenessdetection: ^1.1.15 copied to clipboard
A real-time facial verification feature using Google ML Kit for liveliness detection.
Facelivenessdetection #
A real-time facial verification feature using Google ML Kit for liveliness detection. It ensures user interaction through smiling, blinking, and head movements. Features include face detection, dynamic feedback, a countdown timer, and customizable UI—ideal for secure authentication and anti-spoofisng verification. 🚀
Features #
- Detects user presence with a face detection engine.
- Displays dynamic UI feedback for each rule.
- Animated transitions when detecting face presence.
- Handles countdown timers before validation.
- Efficient state management with rule tracking.
Setup #
iOS #
Uncomment this line to define a global platform for your project #
platform :ios, '15.5.0'
Add two rows to the ios/Runner/Info.plist:
one with the key Privacy - Camera Usage Description and a usage description. and one with the key Privacy - Microphone Usage Description and a usage description. If editing Info.plist as text, add:
<key>NSCameraUsageDescription</key>
<string>your usage description here</string>
<key>NSMicrophoneUsageDescription</key>
<string>your usage description here</string>
Usage #
To use this widget, add it inside a Flutter screen:
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
class FaceVerificationWidget extends StatefulWidget {
@override
_FaceVerificationWidgetState createState() => _FaceVerificationWidgetState();
}
class _FaceVerificationWidgetState extends State<FaceVerificationWidget> {
final List<String> _completedRuleset = [];
@override
Widget build(BuildContext context) {
return FaceDetectorView(
onSuccessValidation: (validated) {},
onChildren: ({required countdown, required state, required hasFace}) {
return [
const SizedBox(height: 20),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset('assets/face_verification_icon.png', height: 30, width: 30),
const SizedBox(width: 10),
Flexible(
child: AnimatedSize(
duration: const Duration(milliseconds: 150),
child: Text(
hasFace ? 'User face found' : 'User face not found',
style: _textStyle,
),
),
),
],
),
const SizedBox(height: 30),
Text(
_rulesetHints[state] ?? 'Please follow instructions',
style: _textStyle.copyWith(fontSize: 20, fontWeight: FontWeight.w600),
),
if (countdown > 0)
Text.rich(
TextSpan(
children: [
const TextSpan(text: 'IN\n'),
TextSpan(
text: countdown.toString(),
style: _textStyle.copyWith(fontSize: 22, fontWeight: FontWeight.w600),
),
],
),
textAlign: TextAlign.center,
style: _textStyle.copyWith(fontSize: 16),
)
else
const Column(
children: [
SizedBox(height: 50),
CupertinoActivityIndicator(),
],
),
];
},
onRulesetCompleted: (ruleset) {
if (!_completedRuleset.contains(ruleset)) {
setState(() => _completedRuleset.add(ruleset));
}
},
);
}
}
/// Text style for UI consistency
const TextStyle _textStyle = TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400,
fontSize: 12,
);
/// Ruleset hints for better performance (eliminating switch-case)
const Map<Rulesets, String> _rulesetHints = {
Rulesets.smiling: 'Please Smile',
Rulesets.blink: 'Please Blink',
Rulesets.tiltUp: 'Please Look Up',
Rulesets.tiltDown: 'Please Look Down',
Rulesets.toLeft: 'Please Look Left',
Rulesets.toRight: 'Please Look Right',
};