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.