face_detector_flutter 1.0.1
face_detector_flutter: ^1.0.1 copied to clipboard
A Flutter plugin for real-time face detection using Google ML Kit and Camera. Provides a simple API to detect faces, validate alignment, and capture the face image as bytes (Uint8List) for authenticat [...]
A simple and lightweight face detection + authentication package built with Flutter. It uses the device camera and ML Kit under the hood to detect faces in real time.
π Installation #
Add the dependency in your pubspec.yaml:
dependencies:
face_detector_flutter: ^1.0.0
π§ Setup #
Android #
Add camera permissions to android/app/src/main/AndroidManifest.xml
:
<uses-permission android:name="android.permission.CAMERA" />
iOS #
Add camera permissions to ios/Runner/Info.plist
:
<key>NSCameraUsageDescription</key>
<string>This app needs camera access for face recognition authentication</string>
π± Example Usage #
class _HomeScreenState extends State<HomeScreen> {
final FaceDetectorController _faceAuthController = FaceDetectorController();
FaceAuthState _faceAuthState = FaceAuthState.initializing;
Uint8List? _bytes;
void _startDetectingFace() async {
await _faceAuthController.initialize();
setState(() {
_faceAuthState = FaceAuthState.cameraOpened;
});
final detectedFaceBytes = await _faceAuthController.detect(
onDetect: (detectionState) {
setState(() => _faceAuthState = detectionState);
},
);
_bytes = detectedFaceBytes;
_faceAuthController.dispose();
}
@override
void initState() {
super.initState();
_startDetectingFace();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text("Simple Face Detection Example"),
),
body: Column(
children: [
if (_bytes == null) Text(_faceAuthState.name),
if (_bytes != null)
Expanded(child: Image.memory(_bytes!))
else
Expanded(child: FaceAuthView(controller: _faceAuthController)),
],
),
);
}
}
π§© Features #
- π· Real-time face detection using device camera
- π Face authentication (based on detection state)
- πΌ Convert detected face to
Uint8List
(display withImage.memory
) - β‘ Lightweight and easy to use
π License #
This project is licensed under the MIT License.