I need to determine the available authentication methods for mobile devices (iOS and Android), but local_auth
leaves some features to be desired. Specifically, the issue I am facing is that all attempts using the local_auth package return BiometricType.strong
and BiometricType.weak
, and not something specific like the enums in the package, such as BiometricType.face
or BiometricType.fingerprint
. I need the specific biometric authentication types.
The only testing environment I have available to me is android studio's emulator, and on each attempted emulated device, pin, pass, and fingerprint were set. I was hoping to see that BiometricType.fingerprint
was returned and displayed.
Here is my test code:
`import 'package:flutter/material.dart';
import 'package:local_auth/local_auth.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final LocalAuthentication _localAuth = LocalAuthentication();
List<BiometricType> _availableBiometrics = [];
@override
void initState() {
super.initState();
_checkBiometrics();
}
Future<void> _checkBiometrics() async {
try {
_availableBiometrics = await _localAuth.getAvailableBiometrics();
} catch (e) {
print("Error checking biometrics availability: $e");
return;
}
setState(() {});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Biometric Authentication'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Available Biometric Authentication Methods:'),
for (var biometricType in _availableBiometrics)
Text(biometricType.toString()),
],
),
),
),
);
}
}`
*Quick note: for those attempting to replicate this code in a fresh Flutter project, visit the bottom of the local_auth readme page so that the android and iOS integrations are included in the AndroidManifest.xml and info.plist, respectively.