dart format
This commit is contained in:
@@ -16,7 +16,6 @@ import 'package:kmobile/features/profile/preferences/preference_screen.dart';
|
||||
import 'package:kmobile/api/services/auth_service.dart';
|
||||
import 'package:kmobile/features/fund_transfer/screens/tpin_set_screen.dart';
|
||||
|
||||
|
||||
class ProfileScreen extends StatefulWidget {
|
||||
final String mobileNumber;
|
||||
const ProfileScreen({super.key, required this.mobileNumber});
|
||||
@@ -38,12 +37,12 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
return 'Version ${info.version} (${info.buildNumber})';
|
||||
}
|
||||
|
||||
Future<void> _loadBiometricStatus() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
setState(() {
|
||||
_isBiometricEnabled = prefs.getBool('biometric_enabled') ?? false;
|
||||
});
|
||||
}
|
||||
Future<void> _loadBiometricStatus() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
setState(() {
|
||||
_isBiometricEnabled = prefs.getBool('biometric_enabled') ?? false;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _handleLogout(BuildContext context) async {
|
||||
final auth = getIt<AuthRepository>();
|
||||
@@ -54,90 +53,90 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
Navigator.pushNamedAndRemoveUntil(context, '/login', (route) => false);
|
||||
}
|
||||
|
||||
Future<void> _handleBiometricToggle(bool enable) async {
|
||||
final localAuth = LocalAuthentication();
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final canCheck = await localAuth.canCheckBiometrics;
|
||||
Future<void> _handleBiometricToggle(bool enable) async {
|
||||
final localAuth = LocalAuthentication();
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final canCheck = await localAuth.canCheckBiometrics;
|
||||
|
||||
if (!canCheck) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context).biometricsNotAvailable)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!canCheck) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context).biometricsNotAvailable)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
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 (enable) {
|
||||
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 prefs.setBool('biometric_enabled', true);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isBiometricEnabled = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Handle exceptions, state remains unchanged.
|
||||
}
|
||||
}
|
||||
} else {
|
||||
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 (optIn == true) {
|
||||
try {
|
||||
final didAuth = await localAuth.authenticate(
|
||||
localizedReason: AppLocalizations.of(context).authenticateToEnable,
|
||||
options: const AuthenticationOptions(
|
||||
stickyAuth: true,
|
||||
biometricOnly: true,
|
||||
),
|
||||
);
|
||||
if (didAuth) {
|
||||
await prefs.setBool('biometric_enabled', true);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isBiometricEnabled = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Handle exceptions, state remains unchanged.
|
||||
}
|
||||
}
|
||||
} else {
|
||||
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 prefs.setBool('biometric_enabled', false);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isBiometricEnabled = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (optOut == true) {
|
||||
await prefs.setBool('biometric_enabled', false);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isBiometricEnabled = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -172,14 +171,14 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title: Text(AppLocalizations.of(context).enableFingerprintLogin),
|
||||
value: _isBiometricEnabled,
|
||||
onChanged: (bool value) {
|
||||
// The state is now managed within _handleBiometricToggle
|
||||
_handleBiometricToggle(value);
|
||||
},
|
||||
secondary: const Icon(Icons.fingerprint),
|
||||
),
|
||||
title: Text(AppLocalizations.of(context).enableFingerprintLogin),
|
||||
value: _isBiometricEnabled,
|
||||
onChanged: (bool value) {
|
||||
// The state is now managed within _handleBiometricToggle
|
||||
_handleBiometricToggle(value);
|
||||
},
|
||||
secondary: const Icon(Icons.fingerprint),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.password),
|
||||
title: Text(loc.changeLoginPassword),
|
||||
@@ -195,55 +194,57 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.password),
|
||||
title: Text('Change TPIN'),
|
||||
onTap: () async {
|
||||
// 1. Get the AuthService instance
|
||||
final authService = getIt<AuthService>();
|
||||
title: Text('Change TPIN'),
|
||||
onTap: () async {
|
||||
// 1. Get the AuthService instance
|
||||
final authService = getIt<AuthService>();
|
||||
|
||||
// 2. Call checkTpin() to see if TPIN is set
|
||||
final isTpinSet = await authService.checkTpin();
|
||||
// 2. Call checkTpin() to see if TPIN is set
|
||||
final isTpinSet = await authService.checkTpin();
|
||||
|
||||
// 3. If TPIN is not set, show the dialog
|
||||
if (!isTpinSet) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text('TPIN Not Set'),
|
||||
content: Text('You have not set a TPIN yet. Please set a TPIN to proceed.'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: Text('Back'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text('Proceed'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(); // Dismiss the dialog
|
||||
// Navigate to the TPIN set screen
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => TpinSetScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
// Case 2: TPIN is set
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangeTpinScreen(mobileNumber: widget.mobileNumber),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
// 3. If TPIN is not set, show the dialog
|
||||
if (!isTpinSet) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text('TPIN Not Set'),
|
||||
content: Text(
|
||||
'You have not set a TPIN yet. Please set a TPIN to proceed.'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: Text('Back'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text('Proceed'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(); // Dismiss the dialog
|
||||
// Navigate to the TPIN set screen
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => TpinSetScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
// Case 2: TPIN is set
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
ChangeTpinScreen(mobileNumber: widget.mobileNumber),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
// ListTile(
|
||||
// leading: const Icon(Icons.password),
|
||||
// title: const Text("Change Login MPIN"),
|
||||
|
||||
Reference in New Issue
Block a user