Smart Selfie Capture

pub package License: MIT Flutter Platform

A comprehensive Flutter package for capturing selfies with advanced features including face validation, liveness checks, and real-time feedback. Perfect for KYC, identity verification, and secure photo capture applications.

โœจ Features

  • ๐ŸŽฏ Real-time Face Detection - Powered by Google ML Kit
  • ๐Ÿ”’ Three Liveness Check Modes - Blink, mouth open, or both
  • ๐Ÿ“ Advanced Face Validation - Size, orientation, eyes, and smile detection
  • ๐ŸŽจ Fully Customizable UI - Colors, messages, instructions, and themes
  • โšก Instant Visual Feedback - Face overlay with corner brackets
  • ๐ŸŒ Cross-platform - iOS 15.5+ and Android 21+
  • ๐Ÿงช Well Tested - 26 unit tests with comprehensive coverage
  • ๐Ÿ“š Complete Documentation - API reference and examples included

๐Ÿ“ธ Screenshots

Basic Selfie Liveness Check Smile Detection
Face detection with overlay Blink or mouth open Smile validation

๐Ÿš€ Quick Start

Installation

Add to your pubspec.yaml:

dependencies:
  smart_selfie_capture: ^0.0.1

Then run:

flutter pub get

Platform-Specific Setup

๐Ÿ“ฑ iOS Setup
  1. Add camera permission to ios/Runner/Info.plist:
<key>NSCameraUsageDescription</key>
<string>Camera access is required to capture your selfie</string>
  1. Set minimum iOS version in ios/Podfile:
platform :ios, '15.5'
  1. Run pod install:
cd ios && pod install
๐Ÿค– Android Setup
  1. Update minimum SDK in android/app/build.gradle:
android {
    defaultConfig {
        minSdkVersion 21
        compileSdkVersion 34
    }
}
  1. Add permissions to android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
  1. Handle camera permissions in your app before opening the capture screen.

๐Ÿ’ก Usage Examples

Basic Selfie Capture

Simple selfie capture with default settings:

import 'package:smart_selfie_capture/smart_selfie_capture.dart';

SelfieCaptureScreen(
  config: const SelfieConfig(
    title: 'Take a Selfie',
    enableLivenessCheck: false,
  ),
  onCaptureComplete: (SelfieResult result) {
    print('Image saved: ${result.imagePath}');
    print('Validated: ${result.isValidated}');
    Navigator.pop(context);
  },
)

Identity Verification with Liveness

Complete verification with mouth opening detection:

SelfieCaptureScreen(
  config: const SelfieConfig(
    title: 'Verify Your Identity',
    subtitle: 'Position your face in the frame',
    enableLivenessCheck: true,
    livenessCheckType: LivenessCheckType.mouthOpen,
    livenessBlinkCount: 1,
    customMessage: 'Please ensure you are in a well-lit area',
    instructions: [
      'Look directly at the camera',
      'Open your mouth when prompted',
      'Hold still during capture',
    ],
    validationRules: ValidationRules(
      requireFrontalFace: true,
      requireEyesOpen: true,
      minFaceSize: 0.4,
      maxFaceSize: 0.7,
    ),
    primaryColor: Colors.blue,
  ),
  onCaptureComplete: (result) {
    if (result.isValidated && result.livenessCheckPassed) {
      // Process verified selfie
      uploadToServer(result.imagePath);
    }
  },
  onCancel: () {
    Navigator.pop(context);
  },
)

Smile Detection

Capture a selfie with smile requirement:

SelfieCaptureScreen(
  config: SelfieConfig(
    title: 'Smile Please! ๐Ÿ˜Š',
    subtitle: 'Show us your best smile',
    validationRules: const ValidationRules(
      requireSmile: true,
      requireEyesOpen: true,
      minFaceSize: 0.35,
    ),
    enableLivenessCheck: false,
    primaryColor: Colors.orange,
  ),
  onCaptureComplete: (result) {
    showDialog(
      context: context,
      builder: (_) => AlertDialog(
        title: Text('Perfect!'),
        content: Image.file(File(result.imagePath)),
      ),
    );
  },
)

๐ŸŽฏ Liveness Check Types

The package supports three liveness detection modes:

Type Description Use Case
LivenessCheckType.blink Detects eye blinks Traditional liveness check
LivenessCheckType.mouthOpen Detects mouth opening Alternative liveness method
LivenessCheckType.both Requires both actions Maximum security

Example:

SelfieConfig(
  enableLivenessCheck: true,
  livenessCheckType: LivenessCheckType.mouthOpen,
  livenessBlinkCount: 1,  // Number of times to perform action
)

โš™๏ธ Configuration Options

SelfieConfig

Property Type Default Description
title String 'Capture Selfie' Screen title
subtitle String 'Position your face...' Subtitle text
instructions List<String> [...] List of instructions
validationRules ValidationRules ValidationRules() Face validation criteria
enableLivenessCheck bool true Enable liveness detection
livenessCheckType LivenessCheckType mouthOpen Type of liveness check
livenessBlinkCount int 2 Required action count
enableObjectDetection bool true Enable object detection
primaryColor Color Colors.blue Primary UI color
backgroundColor Color Colors.black Background color
captureDelay Duration 3 seconds Countdown duration
customMessage String? null Custom banner message

ValidationRules

Fine-tune face validation behavior:

Property Type Default Description
requireFrontalFace bool true Face must look at camera
requireEyesOpen bool true Eyes must be open
requireSmile bool false Smile detection
minFaceSize double 0.3 Min face size (0.0-1.0)
maxFaceSize double 0.8 Max face size (0.0-1.0)
minEulerAngleX/Y/Z double -15.0 Head angle tolerance
maxEulerAngleX/Y/Z double 15.0 Head angle tolerance
allowMultipleFaces bool false Allow multiple faces

Example:

ValidationRules(
  requireFrontalFace: true,
  requireEyesOpen: true,
  minFaceSize: 0.4,      // Face should be 40%+ of frame
  maxFaceSize: 0.7,      // Face should be max 70% of frame
  minEulerAngleY: -15.0, // Allow 15ยฐ left/right turn
  maxEulerAngleY: 15.0,
)

SelfieResult

The capture result contains:

Property Type Description
imagePath String Absolute path to saved image
isValidated bool Face validation status
livenessCheckPassed bool Liveness check status
validationDetails Map Detailed validation data
capturedAt DateTime Capture timestamp

Example:

onCaptureComplete: (SelfieResult result) {
  print('Image: ${result.imagePath}');
  print('Valid: ${result.isValidated}');
  print('Live: ${result.livenessCheckPassed}');
  print('Blinks: ${result.validationDetails['blinkCount']}');
  print('Time: ${result.capturedAt}');
}

๐Ÿ“– Documentation

๐Ÿ”ง Troubleshooting

Camera not initializing
  • Verify camera permissions are granted
  • Check platform-specific setup is complete
  • Ensure device has a working camera
  • Test on physical device (emulators may have issues)
Face not detected
  • Improve lighting conditions
  • Position face in center of frame
  • Remove obstructions (glasses, masks, hats)
  • Ensure face is within size range (30-80% of frame)
  • Check that face is looking at camera
Liveness check not working
  • Ensure good lighting for eye/mouth detection
  • Try different liveness types (blink vs mouth open)
  • Increase livenessBlinkCount threshold
  • Check that eyes/mouth are clearly visible
Performance issues
  • Use ResolutionPreset.medium for older devices
  • Disable enableObjectDetection if not needed
  • Reduce validation strictness
  • Test on physical device (emulators are slower)
ML Kit errors
  • Verify Google Play Services (Android)
  • Check minimum platform requirements
  • Ensure internet connection for first-time ML Kit download
  • Clear app cache and reinstall

๐ŸŽฏ Use Cases

  • ๐Ÿ‘ค KYC Verification - Know Your Customer identity checks
  • ๐Ÿฆ Banking Apps - Secure customer onboarding
  • ๐ŸŽซ Event Check-in - Photo-based attendance
  • ๐Ÿ†” ID Verification - Government ID matching
  • ๐Ÿ‘จโ€โš•๏ธ Healthcare - Patient identification
  • ๐Ÿš— Ride Sharing - Driver verification
  • ๐Ÿข Access Control - Building entry systems

โšก Performance Tips

  1. Resolution: Use medium for faster processing on older devices
  2. Validation: Relax angle tolerances for easier capture
  3. Liveness: Single action is faster than multiple
  4. Object Detection: Disable if not needed for security

๐Ÿ“‹ Requirements

Requirement Minimum Version
Flutter SDK 3.3.0+
Dart SDK 3.9.2+
iOS 15.5+
Android API 21+ (5.0)

๐Ÿš€ How It Works

Process Flow

  1. ๐ŸŽฌ Initialization - Camera and ML Kit face detectors start
  2. ๐Ÿ‘๏ธ Face Detection - Real-time detection on camera stream (30 FPS)
  3. โœ… Validation - Face checked against configured rules:
    • Face size 30-80% of frame (distance check)
    • Head pose within ยฑ15ยฐ (frontal face)
    • Eyes open detection
    • Optional smile detection
  4. ๐Ÿ”ด Liveness Check - Blink or mouth open to prevent photo spoofing
  5. โฑ๏ธ Countdown - 3-second countdown with visual feedback
  6. ๐Ÿ“ธ Capture - High-resolution image captured and saved
  7. ๐Ÿ“ฆ Result - Returns SelfieResult with validation data

Visual Feedback Features

  • โœจ Real-time face overlay with corner brackets
  • ๐ŸŽจ Color-coded status messages (green = good, red = error)
  • โฐ Countdown timer animation
  • ๐Ÿ“Š Scanning animation during detection

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿค Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines on:

  • Code standards and style
  • Testing requirements
  • Pull request process
  • Issue reporting

๐Ÿ“ Changelog

See CHANGELOG.md for version history and release notes.

๐Ÿ› Issues & Support

๐Ÿ™ Acknowledgments

This package is built on top of excellent open-source projects:

  • Google ML Kit - Face detection and classification
  • Camera Plugin - Flutter camera integration
  • Flutter Community - For continuous support and feedback

โญ Show Your Support

If this package helped your project, please:

  • โญ Star the repository on GitHub
  • ๐Ÿ‘ Like it on pub.dev
  • ๐Ÿ“ข Share it with other developers

Made with โค๏ธ for the Flutter community

Libraries

smart_selfie_capture
Smart Selfie Capture - A comprehensive Flutter package for capturing selfies with advanced features including face validation, liveness checks, and real-time feedback.
smart_selfie_capture_method_channel
smart_selfie_capture_platform_interface