Fix biometric switch and UI improvements
This commit is contained in:
@@ -38,9 +38,10 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
}
|
||||
|
||||
Future<void> _loadBiometricStatus() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final storage = getIt<SecureStorage>();
|
||||
final enabled = await storage.read('biometric_enabled');
|
||||
setState(() {
|
||||
_isBiometricEnabled = prefs.getBool('biometric_enabled') ?? false;
|
||||
_isBiometricEnabled = enabled ?? false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -55,14 +56,16 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
|
||||
Future<void> _handleBiometricToggle(bool enable) async {
|
||||
final localAuth = LocalAuthentication();
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final storage = getIt<SecureStorage>();
|
||||
final canCheck = await localAuth.canCheckBiometrics;
|
||||
|
||||
if (!canCheck) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context).biometricsNotAvailable)),
|
||||
);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context).biometricsNotAvailable)),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -96,15 +99,28 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
),
|
||||
);
|
||||
if (didAuth) {
|
||||
await prefs.setBool('biometric_enabled', true);
|
||||
await storage.write('biometric_enabled', true);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isBiometricEnabled = true;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Authentication failed, reload state to refresh UI
|
||||
if (mounted) {
|
||||
await _loadBiometricStatus();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Handle exceptions, state remains unchanged.
|
||||
// Handle exceptions, reload state to ensure consistency
|
||||
if (mounted) {
|
||||
await _loadBiometricStatus();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// User cancelled, reload state to refresh UI
|
||||
if (mounted) {
|
||||
await _loadBiometricStatus();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -128,12 +144,17 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
);
|
||||
|
||||
if (optOut == true) {
|
||||
await prefs.setBool('biometric_enabled', false);
|
||||
await storage.write('biometric_enabled', false);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isBiometricEnabled = false;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// User cancelled, reload state to refresh UI
|
||||
if (mounted) {
|
||||
await _loadBiometricStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user