import 'package:flutter/services.dart';
import 'package:local_auth/local_auth.dart';
import 'package:local_auth_android/local_auth_android.dart';
import 'package:local_auth_ios/local_auth_ios.dart';
class LocalAuthApi {
final _auth = LocalAuthentication();
Future hasBiometrics() async {
try {
return auth.canCheckBiometrics;
} on PlatformException catch () {
return false;
}
}
Future authenticate() async {
final isAvaliable = await hasBiometrics();
if (!isAvaliable) return false;
try {
return auth.authenticate(
localizedReason: 'Scan',
options: const AuthenticationOptions(
biometricOnly: true,
useErrorDialogs: true,
stickyAuth: true),
authMessages: const [
AndroidAuthMessages(
signInTitle: "Authenticate for Login",
cancelButton: 'Cancel',
goToSettingsButton: 'Settings',
goToSettingsDescription: 'Please register your Fingerprint',
),
IOSAuthMessages(
cancelButton: 'Cancel',
),
]
);
} on PlatformException catch () {
return false;
}
}
}