Simplifying Biometric Authentication in Flutter Applications with Simple Biometric
In a world where digital security is paramount, biometric authentication has become an essential tool for protecting our mobile applications. However, integrating this technology can be challenging, especially when dealing with different platforms like Android and iOS. That's why I've developed Simple Biometric, a Flutter library that simplifies this process, allowing developers to easily add biometric authentication to their applications.
The Origin of Simple Biometric
The idea for Simple Biometric came from my personal experience developing mobile applications. I noticed that although biometric authentication adds a layer of security and convenience, the integration process was often cumbersome. Each platform has its nuances, and managing them separately was time-consuming. I wanted to create a solution that would abstract these complexities and provide a unified interface for Flutter developers.
Key Features:
iOS: Simple Biometric can detect if an iOS device has biometric capabilities and determine the type (Face ID or Touch ID). This is useful for customizing the user interface based on the device's capabilities. For example:
IOSBiometricType iosBiometricType = await SimpleBiometric.getIOSBiometricType();
if(iosBiometricType == IOSBiometricType.faceId) {
// Face ID is available
} else if (iosBiometricType == IOSBiometricType.touchId) {
// Touch ID is available
}
Android: The library checks the availability of biometric hardware, regardless of whether it is configured or not. With the following code, you can check if the device has biometric available:
final bool isBiometricAvailable = await SimpleBiometric.isAndroidBiometricHardwareAvailable();
Customization: Simple Biometric allows you to launch the biometric scanner dialog with a custom message, improving the user experience. For example:
try {
BiometricStatusResult? result = await SimpleBiometric.showBiometricPrompt(
title: 'Biometric Authentication',
description: 'Authenticate using your biometric credentials',
cancelText: 'Cancel',
);
switch (result) {
case BiometricStatusResult.authSuccess: // Authentication successful
break;
case BiometricStatusResult.noBiometrics: // No biometrics available
break;
case BiometricStatusResult.noHardware: // Biometric hardware not available
break;
default: // Authentication failed break;
}
} catch (e) { // Handle errors }
Recommended by LinkedIn
How to Use Simple Biometric:
For Android:
import io.flutter.embedding.android.FlutterFragmentActivity;
class MainActivity: FlutterFragmentActivity() {}
<uses-permission android:name="android.permission.USE_BIOMETRIC"/>
For iOS:
<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>
Conclusion:
Simple Biometric is a powerful and easy-to-use tool that can significantly enhance the security of your Flutter applications. With support for both platforms, easy integration, and customizable prompts, this library is an excellent addition to your development toolkit. I hope you find Simple Biometric useful and contribute to its growth and improvement.
To learn more and contribute, visit the Simple Biometric GitLab repository and Simple Biometric on pub.dev.
Muchas Felicidades Brother 💪🏽