Fingerprint option added in profile screen
This commit is contained in:
@@ -4,6 +4,8 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:kmobile/data/repositories/auth_repository.dart';
|
import 'package:kmobile/data/repositories/auth_repository.dart';
|
||||||
import 'package:kmobile/features/profile/change_password/change_password_screen.dart';
|
import 'package:kmobile/features/profile/change_password/change_password_screen.dart';
|
||||||
import 'package:kmobile/features/profile/logout_dialog.dart';
|
import 'package:kmobile/features/profile/logout_dialog.dart';
|
||||||
|
import 'package:kmobile/security/secure_storage.dart';
|
||||||
|
import 'package:local_auth/local_auth.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import '../../di/injection.dart';
|
import '../../di/injection.dart';
|
||||||
import '../../l10n/app_localizations.dart';
|
import '../../l10n/app_localizations.dart';
|
||||||
@@ -18,6 +20,21 @@ class ProfileScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ProfileScreenState extends State<ProfileScreen> {
|
class _ProfileScreenState extends State<ProfileScreen> {
|
||||||
|
bool _isBiometricEnabled = false;
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_loadBiometricStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _loadBiometricStatus() async {
|
||||||
|
final storage = getIt<SecureStorage>();
|
||||||
|
final isEnabled = await storage.read('biometric_enabled');
|
||||||
|
setState(() {
|
||||||
|
_isBiometricEnabled = isEnabled == 'true';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _handleLogout(BuildContext context) async {
|
Future<void> _handleLogout(BuildContext context) async {
|
||||||
final auth = getIt<AuthRepository>();
|
final auth = getIt<AuthRepository>();
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
@@ -27,6 +44,90 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
Navigator.pushNamedAndRemoveUntil(context, '/login', (route) => false);
|
Navigator.pushNamedAndRemoveUntil(context, '/login', (route) => false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Future<void> _handleBiometricToggle(bool enable) async {
|
||||||
|
final localAuth = LocalAuthentication();
|
||||||
|
final storage = getIt<SecureStorage>();
|
||||||
|
final canCheck = await localAuth.canCheckBiometrics;
|
||||||
|
|
||||||
|
if (!canCheck) {
|
||||||
|
// Optional: Show a snackbar or dialog if biometrics are not available
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text(AppLocalizations.of(context).biometricsNotAvailable)),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enable) {
|
||||||
|
// Show "Enable" dialog
|
||||||
|
final optIn = await showDialog<bool>(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (ctx) => AlertDialog(
|
||||||
|
title: Text(AppLocalizations.of(context).enableFingerprintLogin),
|
||||||
|
content: Text(AppLocalizations.of(context).enableFingerprintMessage),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(ctx).pop(false),
|
||||||
|
child: Text(AppLocalizations.of(context).no),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(ctx).pop(true),
|
||||||
|
child: Text(AppLocalizations.of(context).yes),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (optIn == true) {
|
||||||
|
try {
|
||||||
|
final didAuth = await localAuth.authenticate(
|
||||||
|
localizedReason: AppLocalizations.of(context).authenticateToEnable,
|
||||||
|
options: const AuthenticationOptions(
|
||||||
|
stickyAuth: true,
|
||||||
|
biometricOnly: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (didAuth) {
|
||||||
|
await storage.write('biometric_enabled', 'true');
|
||||||
|
setState(() {
|
||||||
|
_isBiometricEnabled = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Handle authentication errors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Show "Disable" dialog
|
||||||
|
final optOut = await showDialog<bool>(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (ctx) => AlertDialog(
|
||||||
|
title: Text(AppLocalizations.of(context).disableFingerprintLogin),
|
||||||
|
content: Text(AppLocalizations.of(context).disableFingerprintMessage),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(ctx).pop(false),
|
||||||
|
child: Text(AppLocalizations.of(context).no),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(ctx).pop(true),
|
||||||
|
child: Text(AppLocalizations.of(context).yes),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (optOut == true) {
|
||||||
|
await storage.write('biometric_enabled', 'false');
|
||||||
|
setState(() {
|
||||||
|
_isBiometricEnabled = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final loc = AppLocalizations.of(context);
|
final loc = AppLocalizations.of(context);
|
||||||
@@ -48,6 +149,14 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
SwitchListTile(
|
||||||
|
title: Text(AppLocalizations.of(context).enableFingerprintLogin),
|
||||||
|
value: _isBiometricEnabled,
|
||||||
|
onChanged: (bool value) {
|
||||||
|
_handleBiometricToggle(value);
|
||||||
|
},
|
||||||
|
secondary: const Icon(Icons.fingerprint),
|
||||||
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.password),
|
leading: const Icon(Icons.password),
|
||||||
title: Text(loc.changeLoginPassword),
|
title: Text(loc.changeLoginPassword),
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// ignore_for_file: unused_element
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../../../l10n/app_localizations.dart';
|
import '../../../l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
|||||||
@@ -328,5 +328,8 @@
|
|||||||
"limitAmount": "Limit Amount",
|
"limitAmount": "Limit Amount",
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
"deregister": "De-Register",
|
"deregister": "De-Register",
|
||||||
"deregistercheck": "Are you sure you want to De-Register?"
|
"deregistercheck": "Are you sure you want to De-Register?",
|
||||||
|
"biometricsNotAvailable": "Biometrics not available on this device",
|
||||||
|
"disableFingerprintLogin": "Disable Fingerprint Login",
|
||||||
|
"disableFingerprintMessage": "Are you sure you want to disable fingerprint login?"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -329,5 +329,8 @@
|
|||||||
"limitAmount": "सीमा राशि",
|
"limitAmount": "सीमा राशि",
|
||||||
"save": "जमा करें",
|
"save": "जमा करें",
|
||||||
"deregister": "अपंजीकृत",
|
"deregister": "अपंजीकृत",
|
||||||
"deregistercheck": "क्या आप वाकई पंजीकरण रद्द करना चाहते हैं??"
|
"deregistercheck": "क्या आप वाकई पंजीकरण रद्द करना चाहते हैं??",
|
||||||
|
"biometricsNotAvailable": "इस डिवाइस पर बायोमेट्रिक्स उपलब्ध नहीं है",
|
||||||
|
"disableFingerprintLogin": "फ़िंगरप्रिंट लॉगिन अक्षम करें",
|
||||||
|
"disableFingerprintMessage": "क्या आप फ़िंगरप्रिंट लॉगिन अक्षम करना चाहते हैं?"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user