simple_biometric 0.0.1 copy "simple_biometric: ^0.0.1" to clipboard
simple_biometric: ^0.0.1 copied to clipboard

A biometric Flutter plugin.

Simple Biometric #

A Flutter plugin for easy implementation of biometric authentication in your Flutter app.

Features #

  • Simple and easy-to-use API for biometric authentication.
  • Supports both Android and iOS platforms.
  • Customizable authentication dialog with title, description, and cancel button text.

Installation #

Add simple_biometric to your pubspec.yaml dependencies:

dependencies:
  simple_biometric: ^1.0.0

Usage #

Import the package:

import 'package:simple_biometric/simple_biometric.dart';

Check Biometric Availability #

Before attempting authentication, check if biometric hardware is available and configured:


bool isAvailable = await
SimpleBiometric.isBiometricAvailable();

Authenticate Using Biometric #

To authenticate using biometric, call the showBiometricPrompt method with optional customization parameters:

try{

 BiometricStatusResult? result = await SimpleBiometric.showBiometricPrompt(
  title: 'Biometric Authentication',
  description: 'Authenticate using your biometric credential',
  cancelText: 'Cancel',
 );

 if (result == BiometricStatusResult.authSuccess) {
  // Authentication successful
 } else if (result == BiometricStatusResult.noBiometrics) {
  // No biometrics available
 } else if (result == BiometricStatusResult.noHardware) {
  // Biometric hardware not available
 } else {
  // Authentication failed or unknown error
 }
}catch(e){

}

iOS Specific: Check Biometric Type #

On iOS, you can check the available biometric type (Face ID or Touch ID):


IOSBiometricType iosBiometricType = await SimpleBiometric.getIOSBiometricType();

if(iosBiometricType == IOSBiometricType.faceId) {
// Face ID is available
} else if (iosBiometricType == IOSBiometricType.touchId) {
// Touch ID is available
}

API Reference #

getPlatformVersion #

Gets the current platform version.

Future<String?> getPlatformVersion()

Returns: A Future<String?> representing the platform version.

showBiometricPrompt #

Displays a biometric authentication dialog.

Future<BiometricStatusResult?> showBiometricPrompt({
String? title,
String? description,
String? cancelText,
})

Parameters:

  • title: The title of the dialog.
  • description: The description of the dialog.
  • cancelText: The text for the cancel button.

Returns: A Future<BiometricStatusResult?> indicating the result of the biometric authentication. Possible values are:

  • BiometricStatusResult.authSuccess if the authentication was successful.
  • BiometricStatusResult.noBiometrics if no biometrics are available.
  • BiometricStatusResult.noHardware if biometric hardware is not available.

getIOSBiometricType #

Gets the available biometric authentication type on iOS.

Future<IOSBiometricType> getIOSBiometricType()

Returns: A Future<IOSBiometricType> representing the biometric authentication type. Possible values are:

  • IOSBiometricType.noBiometrics if no biometrics are available.
  • IOSBiometricType.touchId if Touch ID is available.
  • IOSBiometricType.faceId if Face ID is available.
  • IOSBiometricType.unknown if the biometric authentication type is unknown.
  • IOSBiometricType.none if biometric authentication is not available or not configured.

isAndroidBiometricHardwareAvailable #

Checks if biometric hardware is available on the device.

Future<bool> isAndroidBiometricHardwareAvailable()

Returns: A Future<bool> indicating whether biometric hardware is available.

Example App #

For a complete sample app using Simple Biometric for authentication, see the example directory.

License #

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