SprintLiveness

A Flutter plugin for face liveness detection and secure attendance tracking. Fully supports Android and iOS platforms, with WebView support for other platforms.

Features

  • Real-time Face Detection: Uses ML Kit on Android and native Vision Framework on iOS.
  • Liveness Challenges: Randomized actions (Smile, Blink, Turn Left/Right, Tilt Up/Down) to ensure the user is live.
  • Clock In System: Secure attendance tracking with geofencing and face verification.
  • Optional Endpoint Integration: Send clock-in data directly to your server with custom payloads and headers.
  • Dynamic UI: Customizable titles, messages, and theme colors.
  • Cross-platform: Support for Android and iOS, with a fallback WebView implementation for Web and Desktop.

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  sprintliveness: ^0.1.1

Then run:

flutter pub get

Platform Requirements

Android

  • Minimum SDK: 21 (Android 5.0)
  • Camera and Location permissions required.

Add these permissions to your android/app/src/main/AndroidManifest.xml:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

iOS

  • Minimum iOS version: 15.5
  • Camera and Location permissions required.

Add these permissions to your ios/Runner/Info.plist:

<key>NSCameraUsageDescription</key>
<string>This app needs camera access for face liveness detection</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs location access for attendance verification</string>

Usage

First, import the package:

import 'package:sprintliveness/sprintliveness.dart';

1. Basic Liveness Check

final _plugin = Sprintliveness();

Future<void> _startCheck(BuildContext context) async {
  final LivenessResult result = await _plugin.startLivenessCheck(context);

  if (result.isSuccess) {
    print('Success! Image: ${result.image}');
  } else {
    print('Error: ${result.exception?.message}');
  }
}

2. Secure Clock In (Check In)

Future<void> _clockIn(BuildContext context) async {
  final config = ClockInConfig(
    title: 'Ajibade Toluwani',
    primaryColor: Colors.green,
    resumptionTime: TimeOfDay(hour: 9, minute: 0),
    targetLatitude: 6.5244,
    targetLongitude: 3.3792,
    locationRadius: 500, // 500 meters
    onProcess: (Map<String, dynamic> data) async {
      // Perform your app-side API call here
      // data contains: image, latitude, longitude, timestamp, is_late
      return ClockInProcessResult.success();
    },
  );

  final ClockInResult result = await _plugin.startClockIn(context, config);

  if (result.isSuccess) {
    print('Clocked in at: ${result.clockInTime}');
    print('Late status: ${result.isLate}');
  }
}

API Reference

Sprintliveness

  • startLivenessCheck(context): Quick face verification.
  • startClockIn(context, config): Multi-step attendance process.

ClockInConfig

Property Description
title Screen title (e.g., Employee Name).
primaryColor Theme color for buttons and rings.
resumptionTime Cut-off time for "In-time" vs "Late".
targetLatitude/Longitude Coordinates for geofencing.
locationRadius Allowed distance from target in meters.
skipLocation If true, starts directly from camera.
onProcess Callback for app-side processing (e.g., API calls).

ClockInResult

  • isSuccess: Boolean check for completion.
  • image: Base64 captured image.
  • clockInTime: Timestamp of completion.
  • isLate: Boolean flag based on resumptionTime.
  • latitude/longitude: The coordinates at the time of clock-in.

License

This project is licensed under the MIT License.

Support

For support and questions, please visit our homepage.