-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal_auth.dart
32 lines (26 loc) · 879 Bytes
/
local_auth.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// ignore_for_file: unnecessary_getters_setters
import 'package:local_auth/local_auth.dart';
import 'package:flutter/services.dart';
class LocalAuthenticationService {
LocalAuthentication _auth = LocalAuthentication();
bool _isProtectionEnabled = false;
bool get isProtectionEnabled => _isProtectionEnabled;
set isProtectionEnabled(bool enabled) => _isProtectionEnabled = enabled;
bool isAuthenticated = false;
Future<void> authenticate() async {
if (_isProtectionEnabled) {
try {
isAuthenticated = await _auth.authenticate(
localizedReason:
'Scan your fingerprint (or face or whatever) to authenticate',
options: const AuthenticationOptions(
stickyAuth: true,
biometricOnly: true,
),
);
} on PlatformException catch (e) {
print(e);
}
}
}
}