'How to detect specific Flutter BiometricType (touch or face ID) using local_auth 2.0.0
I'm implementing fingerprint and face recognition in my flutter app using local_auth 2.0.0. When calling getBiometrics() the docs list the following as available types:
/// Various types of biometric authentication.
/// Some platforms report specific biometric types, while others report only
/// classifications like strong and weak.
enum BiometricType {
/// Face authentication.
face,
/// Fingerprint authentication.
fingerprint,
/// Iris authentication.
iris,
/// Any biometric (e.g. fingerprint, iris, or face) on the device that the
/// platform API considers to be strong. For example, on Android this
/// corresponds to Class 3.
strong,
/// Any biometric (e.g. fingerprint, iris, or face) on the device that the
/// platform API considers to be weak. For example, on Android this
/// corresponds to Class 2.
weak,
}
My device (Android, Moto G7) only returns BiometricType.weak
and BiometricType.strong
- even though it supports fingerprint.
I want to check which types are available, and offer the user to login via either face or fingerprint ID. How can I be sure which is supported by the device in this case?
Solution 1:[1]
As per documentation, You could get all the available biometric types available for the device
To get a list of enrolled biometrics, call getAvailableBiometrics:
List<BiometricType> availableBiometrics =
await auth.getAvailableBiometrics();
if (availableBiometrics.contains(BiometricType.face)) {
// Face ID.
} else if (availableBiometrics.contains(BiometricType.fingerprint)) {
// Touch ID.
}
Solution 2:[2]
Since the local_auth
version 2.0.0, getAvailableBiometrics
only returns weak
and strong
biometric types for Android platform.
Now getAvailableBiometrics
on Android platform returns only enrolled biometric types available on device.
Read more about measuring biometric unlock security: https://source.android.com/security/biometric/measure
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | suzan |
Solution 2 | Nikita Linkov |