flutter_tflite_mobile 3.0.0 copy "flutter_tflite_mobile: ^3.0.0" to clipboard
flutter_tflite_mobile: ^3.0.0 copied to clipboard

A Flutter package for face detection, liveness verification, and document scanning using TensorFlow Lite and Google ML Kit. Supports identity verification with face capture sequences and DNI document [...]

Flutter TFLite Mobile #

A Flutter package for face detection, liveness verification, and document scanning using TensorFlow Lite and Google ML Kit. Supports identity verification with face capture sequences and DNI document scanning for iOS and Android.

Features #

  • Face Detection: Real-time face detection using Google ML Kit
  • Liveness Verification: Captures face positions (center, up, down, left, right) to verify user presence
  • Document Scanning: DNI (ID document) front and back capture with guided frames
  • Selfie Capture: Close and far distance selfies for biometric validation
  • State Management: Built-in BLoC pattern for managing capture states
  • Cross-platform: Supports both iOS and Android

Installation #

Add this to your pubspec.yaml:

dependencies:
  flutter_tflite_mobile: ^2.0.0

Then run:

flutter pub get

Platform Setup #

Android #

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

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Set minimum SDK version in android/app/build.gradle:

android {
    defaultConfig {
        minSdkVersion 21
    }
}

iOS #

Add the following to your ios/Runner/Info.plist:

<key>NSCameraUsageDescription</key>
<string>This app requires camera access for face detection and document scanning.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app requires photo library access to save captured images.</string>

Usage #

Basic Setup #

import 'package:flutter_tflite_mobile/flutter_tflite_mobile.dart';

void main() {
  runApp(MyApp());
}

Face Detection View #

import 'package:flutter_tflite_mobile/flutter_tflite_mobile.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class MyFaceDetectionScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) => ReconocimientoBloc(apiRest: yourApiRestInstance),
      child: FaceDetectorView(),
    );
  }
}

Document Scanning #

import 'package:flutter_tflite_mobile/flutter_tflite_mobile.dart';

class MyDocumentScanScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CamaraParaDocumento(
      redireccion: '/home',
    );
  }
}

Using the BLoC #

// Initialize recognition
context.read<ReconocimientoBloc>().add(OnInitReconocimiento());

// Capture front document image
context.read<ReconocimientoBloc>().add(OnCapturaImagenFrontal(image: imageBytes));

// Capture back document image
context.read<ReconocimientoBloc>().add(OnCapturaImagenTrasero(image: imageBytes));

// Upload images
context.read<ReconocimientoBloc>().add(OnUploadImage(isSelfie: false));

// Listen to state changes
BlocListener<ReconocimientoBloc, ReconocimientoState>(
  listener: (context, state) {
    if (state.error.isNotEmpty) {
      // Handle error
    }
    if (state.accion == ReconocimientoBloc.onUploadImageDocumento) {
      // Document uploaded successfully
    }
  },
  child: YourWidget(),
)

Configuration #

Before using the package, configure your environment in lib/bloc/global/environment.dart:

class Environment {
  static const String clientId = 'YOUR_CLIENT_ID';
  static const String clientSecret = 'YOUR_CLIENT_SECRET';
  static const String originColeccion = 'YOUR_ORIGIN_COLLECTION';
}

And in lib/private/env.dart:

class Env {
  static const String endpointApi = 'YOUR_API_ENDPOINT';
  static const String endpointAuth = 'YOUR_AUTH_ENDPOINT';
  static const String endpointSocket = 'YOUR_SOCKET_ENDPOINT';
}

Face Detection Flow #

  1. Mirror Detection: User rotates head to establish camera orientation
  2. Sequence Capture: Captures 5 face positions (center, up, down, left, right)
  3. Liveness Verification: Takes close and far selfies
  4. Validation: Uploads images to backend API for biometric verification

Dependencies #

This package depends on the following packages:

  • google_mlkit_face_detection: Face detection with ML Kit
  • camera: Camera integration
  • flutter_bloc: State management
  • vibration: Haptic feedback
  • permission_handler: Permission management
  • image_picker: Manual image capture fallback

Platforms #

Platform Support
Android
iOS
Web
Windows
macOS
Linux

License #

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

Contributing #

Contributions are welcome!

Issues #

If you find any issues, please report them on the pub.flutter-io.cn issue tracker.

0
likes
140
points
207
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for face detection, liveness verification, and document scanning using TensorFlow Lite and Google ML Kit. Supports identity verification with face capture sequences and DNI document scanning for iOS and Android.

Repository

Documentation

API reference

License

MIT (license)

Dependencies

api_rest_flutter_mobile, auth_api_rest_mobile, camera, camera_android, cupertino_icons, device_info_plus, equatable, flutter, flutter_bloc, flutter_crud_esquemas_dynamicos_mobile, flutter_http_provider, flutter_models_provider, flutter_utils_providers, font_awesome_flutter, go_router, google_mlkit_commons, google_mlkit_face_detection, image, image_picker, path_provider, permission_handler, vibration, view_ui_flutter

More

Packages that depend on flutter_tflite_mobile