How minhtritc97/livelyness_detection works
Project Overview & Primary Goal
• This project is a Flutter package built to offer liveness detection for facial biometrics. Its core purpose is to differentiate between a live user and spoofing attempts (e.g., photos, recordings, masks) during face recognition.
• The README indicates multi-platform support (iOS, Android, macOS, Web, Linux, Windows) and includes both Flutter code in the “lib” directory and native setup details in the “example” project directories.
Key Components
A. Flutter Plugin Layer (Main API)
• The entry points can be seen in files like lib/index.dart and lib/livelyness_detection.dart. These expose the public API (for example, the call to LivelynessDetection.instance.detectLivelyness).
• This layer as the “LivenessDetection Plugin API” which mediates between the consumer app and internal processing.
B. Core Functionality & Business Logic
• Constants (asset_constants.dart, string_constants.dart)
• Helpers and Extensions (math_helper.dart, ml_helper.dart, extensions like double_extension.dart)
• Models (face_detection_model.dart, livelyness_step_item.dart, detection_threshold.dart) that represent data structures.
C. UI / Presentation Layer
• The UI components and screen management code are located under lib/src/screens (camera_preview.dart, detection_widget.dart, livelyness detection screens).
• This part leverages Flutter’s UI framework to display instructions and animations (see also references to Lottie animations within lib/src/assets/lottie).
D. Platform-Specific (Native) Integration
• The “example” folder includes detailed native project structures for Android, iOS, and other platforms. These parts are responsible for:
• Accessing native device capabilities (camera, microphone permissions as set up in iOS/Android config files).
• Routing method channel calls from Flutter to native code.
• Components for “Platform Channels & Native Implementations” that represent the interaction between Flutter and underlying native code using Method Channels.
E. Plugin Infrastructure & Cross-Platform Support
• Folder structure under “example” indicates support for various platforms (android, ios, linux, macos, windows, web).
• Into a “Platform Support Layer” that serves as connectors between the Flutter app and the specific native implementations.
Relationships and Data Flow
• The Flutter Plugin (API layer) passes the detection configuration (via DetectionConfig and list of LivelynessStepItem) to the Core Module.
• The Core Module then manages the UI flow. It triggers the device camera using the native interface and displays the corresponding liveness detection steps (e.g., blink, smile) using custom painters and UI overlays.
• This communication might use platform channels to invoke relevant native functionalities (configured in the android and ios directories).
• Once complete, the native layer returns a response (often a captured image’s temporary path or result) to the Flutter Plugin, which then relays it back to the client.
Architectural Patterns and Design Principles
• Plugin Architecture: Clearly separates the cross-platform Flutter code from native platform-specific implementations.
• Modular Design: Each module (UI, core, native integration) is self-contained. This modularity is evident in the file structure with separate directories for constants, models, helpers, and screens.
• Dependency Injection/Abstraction: Although not explicitly detailed, the structure implies abstraction between interface definition (platform interface files) and concrete implementations.
• Multi-Platform Support: The same core API is designed to work across several native platforms, as demonstrated by extensive example setups for Android, iOS, macOS, Linux, etc.