Original README snapshot from the linked source repository. Visit the repository for the latest content.
BiometricX
The easy way to use biometric authentication in your Flutter app.
Supports Fingerprint, FaceID and Iris.
Demo APK.

Starting
$ flutter pub add biometricx
Configuration
Change your android MainActivity to extends FlutterFragmentActivity.
import io.flutter.embedding.android.FlutterFragmentActivity
// kotlin
class MainActivity: FlutterFragmentActivity() {
...
}
import io.flutter.embedding.android.FlutterFragmentActivity;
// java
class MainActivity extends FlutterFragmentActivity {
...
}
Usage
To check biometric type of your device.
BiometricType type = await BiometricX.type;
Here is the list of biometric types.
BiometricType.FACE
BiometricType.FINGERPRINT
BiometricType.IRIS
BiometricType.MULTIPLE
BiometricType.NONE
BiometricType.NO_HARDWARE
BiometricType.UNAVAILABLE
BiometricType.UNSUPPORTED
To check if your device can use biometric authentication.
bool isBiometricEnabled = await BiometricX.isEnabled;
To encrypt data using biometric authentication.
BiometricResult result = await BiometricX.encrypt({
biometricKey: 'salkuadrat',
message: 'This is a very secret message',
});
if (result.isSuccess && result.hasData) {
String messageKey = result.data!;
} else {
showToast(result.errorMsg, context: context);
}
If you need a persistent messageKey, you can supply it as parameter to encrypt.
BiometricResult result = await BiometricX.encrypt({
biometricKey: 'salkuadrat',
messageKey: 'secret_message',
message: 'This is a very secret message',
});
if (result.isSuccess && result.hasData) {
String messageKey = result.data!;
} else {
showToast(result.errorMsg, context: context);
}
To decrypt data using biometric authentication.
BiometricResult result = await BiometricX.decrypt({
biometricKey: 'salkuadrat',
messageKey: messageKey,
});
if (result.isSuccess && result.hasData) {
String message = result.data!;
} else {
showToast(result.errorMsg, context: context);
}
To show custom message in your biometric prompt, method encrypt and decrypt have parameters you can use to change the biometric prompt dialog.
BiometricResult result = await BiometricX.encrypt({
biometricKey: 'salkuadrat',
message: 'This is a very secret message',
title: 'Biometric Encryption',
subtitle: 'Enter biometric credentials to encrypt your message',
description: 'Scan fingerprint or face.',
negativeButtonText: 'USE PASSWORD',
confirmationRequired: true,
});
BiometricResult message = await BiometricX.decrypt({
biometricKey: 'salkuadrat',
messageKey: messageKey,
title: 'Biometric Decryption',
subtitle: 'Enter biometric credentials to decrypt your message',
description: 'Scan fingerprint or face.',
negativeButtonText: 'USE PASSWORD',
confirmationRequired: true,
});
Example
Example project.
Demo APK.