Files
Casha/lib/core/services/biometric_service.dart
2026-03-20 20:50:26 +03:00

38 lines
1.0 KiB
Dart

import 'package:local_auth/local_auth.dart';
import 'package:shared_preferences/shared_preferences.dart';
class BiometricService {
static final _auth = LocalAuthentication();
static const _key = 'biometric_enabled';
static Future<bool> isAvailable() async {
final canCheck = await _auth.canCheckBiometrics;
final isSupported = await _auth.isDeviceSupported();
return canCheck && isSupported;
}
static Future<bool> isEnabled() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getBool(_key) ?? false;
}
static Future<void> setEnabled(bool value) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_key, value);
}
static Future<bool> authenticate() async {
try {
return await _auth.authenticate(
localizedReason: 'Confirm your identity to open Casha',
options: const AuthenticationOptions(
biometricOnly: false,
stickyAuth: true,
),
);
} catch (_) {
return false;
}
}
}