You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Dart
		
	
| import 'package:local_auth/local_auth.dart';
 | |
| 
 | |
| import 'logger_service.dart';
 | |
| 
 | |
| class LocalAuthService {
 | |
|   final LocalAuthentication localAuth;
 | |
|   final LoggerService loggerService;
 | |
|   LocalAuthService({required this.localAuth, required this.loggerService});
 | |
|   Future<bool> authenticate() async {
 | |
|     try {
 | |
|       final canCheck = await localAuth.canCheckBiometrics;
 | |
|       final isDeviceSupported = await localAuth.isDeviceSupported();
 | |
| 
 | |
|       if (!canCheck || !isDeviceSupported) {
 | |
|         return false;
 | |
|       }
 | |
| 
 | |
|       final isAuthenticated = await localAuth.authenticate(
 | |
|         localizedReason: 'Please authenticate to proceed',
 | |
|         options: const AuthenticationOptions(
 | |
|           biometricOnly: true,
 | |
|           stickyAuth: true,
 | |
|         ),
 | |
|       );
 | |
| 
 | |
|       return isAuthenticated;
 | |
|     } catch (e) {
 | |
|      print(e);
 | |
|       return false;
 | |
|     }
 | |
|   }
 | |
| 
 | |
| 
 | |
|   Future<bool> canCheckBiometrics() async {
 | |
|     try {
 | |
|       return await localAuth.canCheckBiometrics;
 | |
|     } catch (e) {
 | |
|       return false;
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   Future<List<BiometricType>> getAvailableBiometrics() async {
 | |
|     try {
 | |
|       return await localAuth.getAvailableBiometrics();
 | |
|     } catch (e) {
 | |
|       return [];
 | |
|     }
 | |
|   }
 | |
| } |