Last updated:
0 purchases
simple biometric
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.
Preliminary Configurations #
To use the "simple_biometric" Flutter library, please follow these preliminary configurations for Android and iOS:
For Android: #
In the main Android file, add the following import and class:
import io.flutter.embedding.android.FlutterFragmentActivity;
class MainActivity: FlutterFragmentActivity() {
}
copied to clipboard
In the Android manifest, add the following permission:
<uses-permission android:name="android.permission.USE_BIOMETRIC"/>
copied to clipboard
For iOS: #
In the Info.plist file, add the following keys and descriptions:
<key>NSFaceIDUsageDescription</key>
<string>This app requires facial authentication to access certain functionalities.</string>
<key>NSTouchIDUsageDescription</key>
<string>This app requires fingerprint authentication to access certain functionalities.</string>
copied to clipboard
Usage #
Import the package:
import 'package:simple_biometric/simple_biometric.dart';
copied to clipboard
Android Specific: Check Biometric is available #
Before attempting authentication, check if biometric hardware is available:
final isBiometricAvailable = await _simpleBiometric.isAndroidBiometricHardwareAvailable();
copied to clipboard
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
}
copied to clipboard
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',
);
switch (result) {
case BiometricStatusResult.authSuccess:
log('Authentication successful');
break;
case BiometricStatusResult.noBiometrics:
log('No biometrics available');
break;
case BiometricStatusResult.noHardware:
log('Biometric hardware not available');
break;
case BiometricStatusResult.authFailed:
log('Authentication failed');
break;
case BiometricStatusResult.biometricLockout:
// (iOS does not distinguish between temporary and permanent lockout; it only returns this status. Android only displays this message once and then shows "No biometrics available.")
log('Biometric lockout');
break;
case BiometricStatusResult.biometricLockoutPermanent:
// (Android only displays this message once and then shows "No biometrics available." iOS does not return this status.)
log('Biometric lockout permanent');
break;
default:
if (Platform.isIOS && _biometricType.isNotEmpty) {
log('Authentication config unavailable');
_showConfigBiometricDialog();
}
break;
}
} catch (e) {
}
copied to clipboard
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.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.