fingerprint_plugin 1.0.0+1 copy "fingerprint_plugin: ^1.0.0+1" to clipboard
fingerprint_plugin: ^1.0.0+1 copied to clipboard

A Flutter plugin for biometric authentication with automatic fingerprint detection on Android.

Fingerprint Plugin for Flutter #

pub package License: MIT

A Flutter plugin that provides biometric authentication with automatic fingerprint detection for Android.

Features #

  • Automatic fingerprint detection on app launch
  • No button press required
  • Real-time authentication feedback
  • Simple and intuitive API
  • Supports Android's biometric authentication

Installation #

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

dependencies:
  fingerprint_plugin: ^1.0.0

Usage #

Import the package #

import 'package:fingerprint_plugin/fingerprint_plugin.dart';

Check biometric availability #

bool isAvailable = await FingerprintPlugin.checkBiometrics();

Start authentication #

bool isAuthenticated = await FingerprintPlugin.authenticate();

Example #

import 'package:flutter/material.dart';
import 'package:fingerprint_plugin/fingerprint_plugin.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool _isLoading = true;
  String _statusMessage = 'Initializing...';
  bool _isAuthenticated = false;

  @override
  void initState() {
    super.initState();
    _startFingerprintDetection();
  }

  Future<void> _startFingerprintDetection() async {
    try {
      final isAvailable = await FingerprintPlugin.checkBiometrics();
      
      if (!isAvailable) {
        setState(() {
          _statusMessage = 'Biometric sensor not available';
          _isLoading = false;
        });
        return;
      }

      setState(() {
        _isLoading = false;
        _statusMessage = 'Place your finger on the sensor';
      });

      while (mounted) {
        try {
          final isAuthenticated = await FingerprintPlugin.authenticate();
          
          setState(() {
            _isAuthenticated = isAuthenticated;
            _statusMessage = isAuthenticated 
                ? '✅ Authentication successful!' 
                : '❌ Fingerprint not recognized';
          });
          
          if (isAuthenticated) {
            await Future.delayed(const Duration(seconds: 2));
          }
          
          if (mounted) {
            setState(() {
              _statusMessage = 'Place your finger on the sensor';
              _isAuthenticated = false;
            });
          }
        } catch (e) {
          if (mounted) {
            setState(() {
              _statusMessage = 'Error: ${e.toString()}';
            });
          }
          await Future.delayed(const Duration(seconds: 1));
        }
      }
    } catch (e) {
      setState(() {
        _statusMessage = 'Error accessing sensor: ${e.toString()}';
        _isLoading = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Icon(
              _isAuthenticated ? Icons.verified : Icons.fingerprint,
              size: 80,
              color: _isLoading 
                  ? Colors.grey
                  : _isAuthenticated 
                      ? Colors.green
                      : Colors.blue,
            ),
            const SizedBox(height: 24),
            Text(
              _statusMessage,
              style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
              textAlign: TextAlign.center,
            ),
            if (_isLoading) ...[
              const SizedBox(height: 24),
              const CircularProgressIndicator(),
            ],
          ],
        ),
      ),
    );
  }
}

Android Setup #

Add the following permissions to your AndroidManifest.xml:

<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

License #

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

1
likes
150
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for biometric authentication with automatic fingerprint detection on Android.

Repository (GitHub)

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on fingerprint_plugin

Packages that implement fingerprint_plugin