Biometric Auth
parent
7c84037601
commit
cec6d171e0
@ -0,0 +1,56 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
abstract class CommonAuthServices {
|
||||||
|
Future<bool> authenticate();
|
||||||
|
|
||||||
|
Future<List<BiometricType>> getAvailBio();
|
||||||
|
}
|
||||||
|
|
||||||
|
class CommonAuthImp implements CommonAuthServices {
|
||||||
|
final LocalAuthentication localAuth = LocalAuthentication();
|
||||||
|
|
||||||
|
Future<bool> authenticate() async {
|
||||||
|
try {
|
||||||
|
final availableBiometrics = await localAuth.getAvailableBiometrics();
|
||||||
|
if (availableBiometrics == null || availableBiometrics.isEmpty) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final didAuthenticate = await localAuth.authenticate(
|
||||||
|
localizedReason: "Scan your fingerprint or face ID to authenticate",
|
||||||
|
options: const AuthenticationOptions(
|
||||||
|
stickyAuth: false,
|
||||||
|
biometricOnly: true,
|
||||||
|
sensitiveTransaction: true,
|
||||||
|
useErrorDialogs: true,
|
||||||
|
),
|
||||||
|
authMessages: [
|
||||||
|
const AndroidAuthMessages(
|
||||||
|
cancelButton: 'Cancel',
|
||||||
|
biometricHint: 'Please use your fingerprint or face ID',
|
||||||
|
goToSettingsButton: 'Settings',
|
||||||
|
goToSettingsDescription: 'Please set up your Touch ID.',
|
||||||
|
),
|
||||||
|
const IOSAuthMessages(
|
||||||
|
cancelButton: 'Cancel',
|
||||||
|
goToSettingsButton: 'Settings',
|
||||||
|
goToSettingsDescription: 'Please set up your Touch ID.',
|
||||||
|
lockOut: 'Please reenable your Touch ID',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
return didAuthenticate;
|
||||||
|
} on PlatformException catch (e) {
|
||||||
|
print('Error during authentication: $e');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<BiometricType>> getAvailBio() async {
|
||||||
|
return await localAuth.getAvailableBiometrics();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue