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 [...]

example/example.dart

// ignore_for_file: avoid_print

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_tflite_mobile/flutter_tflite_mobile.dart';
import 'package:api_rest_flutter_mobile/api_rest.dart';

/// Example application demonstrating flutter_tflite_mobile usage
void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter TFLite Mobile Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
        useMaterial3: true,
      ),
      home: const HomeScreen(),
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Flutter TFLite Mobile'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton.icon(
              onPressed: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => const FaceDetectionExample(),
                  ),
                );
              },
              icon: const Icon(Icons.face),
              label: const Text('Face Detection'),
            ),
            const SizedBox(height: 20),
            ElevatedButton.icon(
              onPressed: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => const DocumentScanExample(),
                  ),
                );
              },
              icon: const Icon(Icons.document_scanner),
              label: const Text('Document Scanning'),
            ),
          ],
        ),
      ),
    );
  }
}

/// Example of Face Detection usage
class FaceDetectionExample extends StatelessWidget {
  const FaceDetectionExample({super.key});

  @override
  Widget build(BuildContext context) {
    // Note: You need to provide your own ApiRest instance
    // configured with your backend endpoints
    return BlocProvider(
      create: (context) => ReconocimientoBloc(
        apiRest: _createApiRest(),
      )..add(OnInitReconocimiento()),
      child: BlocListener<ReconocimientoBloc, ReconocimientoState>(
        listener: (context, state) {
          if (state.error.isNotEmpty) {
            ScaffoldMessenger.of(context).showSnackBar(
              SnackBar(content: Text('Error: ${state.error}')),
            );
          }

          if (state.accion == ReconocimientoBloc.onUploadImageSelfie) {
            if (state.responseValdiacionSelfie.isNotEmpty) {
              print('Selfie validation response: ${state.responseValdiacionSelfie}');
              ScaffoldMessenger.of(context).showSnackBar(
                const SnackBar(content: Text('Face validation completed!')),
              );
            }
          }
        },
        child: const FaceDetectorView(),
      ),
    );
  }
}

/// Example of Document Scanning usage
class DocumentScanExample extends StatelessWidget {
  const DocumentScanExample({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) => ReconocimientoBloc(
        apiRest: _createApiRest(),
      )..add(OnInitReconocimiento()),
      child: BlocListener<ReconocimientoBloc, ReconocimientoState>(
        listener: (context, state) {
          if (state.error.isNotEmpty) {
            ScaffoldMessenger.of(context).showSnackBar(
              SnackBar(content: Text('Error: ${state.error}')),
            );
          }

          if (state.accion == ReconocimientoBloc.onUploadImageDocumento) {
            if (state.responseValdiacionDocumento.isNotEmpty) {
              print('Document validation response: ${state.responseValdiacionDocumento}');
              ScaffoldMessenger.of(context).showSnackBar(
                const SnackBar(content: Text('Document validation completed!')),
              );
              Navigator.pop(context);
            }
          }
        },
        child: const CamaraParaDocumento(redireccion: '/'),
      ),
    );
  }
}

/// Create ApiRest instance - Replace with your actual configuration
ApiRest _createApiRest() {
  // TODO: Configure with your actual API endpoints
  // This is a placeholder - you need to provide your own ApiRest configuration
  throw UnimplementedError(
    'You need to configure ApiRest with your backend endpoints. '
    'See the package documentation for configuration details.',
  );
}
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