Profile Screen

This commit is contained in:
2025-11-18 11:33:22 +05:30
parent 71e0521dec
commit fda5d075ff
5 changed files with 498 additions and 147 deletions

View File

@@ -15,7 +15,9 @@ import 'package:kmobile/features/profile/preferences/preference_screen.dart';
class ProfileScreen extends StatefulWidget {
final String mobileNumber;
const ProfileScreen({super.key, required this.mobileNumber});
final String customerNo;
final String customerName;
const ProfileScreen({super.key, required this.mobileNumber, required this.customerNo, required this.customerName});
@override
State<ProfileScreen> createState() => _ProfileScreenState();
@@ -157,80 +159,352 @@ class _ProfileScreenState extends State<ProfileScreen> {
}
}
@override
Widget build(BuildContext context) {
final loc = AppLocalizations.of(context);
// @override
// Widget build(BuildContext context) {
// final loc = AppLocalizations.of(context);
return Scaffold(
appBar: AppBar(
title: Text(loc.profile), // Localized "Profile"
),
body: Stack(
children: [
ListView(
children: [
ListTile(
leading: const Icon(Icons.settings),
title: Text(loc.preferences),
trailing: const Icon(Icons.chevron_right),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const PreferenceScreen()),
);
},
// return Scaffold(
// appBar: AppBar(
// title: Text(loc.profile), // Localized "Profile"
// ),
// body: Stack(
// children: [
// ListView(
// children: [
// ListTile(
// leading: const Icon(Icons.settings),
// title: Text(loc.preferences),
// trailing: const Icon(Icons.chevron_right),
// onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => const PreferenceScreen()),
// );
// },
// ),
// ListTile(
// leading: const Icon(Icons.security),
// title: Text(loc.securitySettings),
// trailing: const Icon(Icons.chevron_right),
// onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => SecuritySettingsScreen(
// mobileNumber: widget.mobileNumber,
// ),
// ),
// );
// },
// ),
// ListTile(
// leading: const Icon(Icons.currency_rupee),
// title: Text(AppLocalizations.of(context).dailylimit),
// onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => const DailyLimitScreen()),
// );
// },
// ),
// 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),
// ),
// ListTile(
// leading: const Icon(Icons.smartphone),
// title: const Text("App Version"),
// trailing: FutureBuilder<String>(
// future: _getAppVersion(),
// builder:
// (BuildContext context, AsyncSnapshot<String> snapshot) {
// if (snapshot.connectionState == ConnectionState.waiting) {
// // Show a loading indicator while waiting for the future to complete
// return const CircularProgressIndicator();
// } else if (snapshot.hasError) {
// return const Text("Error");
// } else {
// // Display the version number once the future is complete
// return Text(
// snapshot.data ?? "N/A",
// selectionColor: const Color(0xFFFFFFFF),
// );
// }
// },
// ),
// ),
// ListTile(
// leading: const Icon(Icons.exit_to_app),
// title: Text(AppLocalizations.of(context).logout),
// onTap: () async {
// final shouldExit = await showDialog<bool>(
// context: context,
// builder: (context) => AlertDialog(
// title: Text(AppLocalizations.of(context).logout),
// content: Text(AppLocalizations.of(context).logoutCheck),
// actions: [
// TextButton(
// onPressed: () => Navigator.of(context).pop(false),
// child: Text(AppLocalizations.of(context).no),
// ),
// TextButton(
// onPressed: () => Navigator.of(context).pop(true),
// child: Text(AppLocalizations.of(context).yes),
// ),
// ],
// ),
// );
// if (shouldExit == true) {
// if (Platform.isAndroid) {
// SystemNavigator.pop();
// }
// exit(0);
// }
// },
// ),
// ListTile(
// leading: const Icon(Icons.logout),
// title: Text(AppLocalizations.of(context).deregister),
// onTap: () async {
// final shouldLogout = await showDialog<bool>(
// context: context,
// builder: (_) => const LogoutDialog(),
// );
// if (shouldLogout == true) {
// await _handleLogout(context);
// }
// },
// ),
// ],
// ),
// IgnorePointer(
// child: Center(
// child: Opacity(
// opacity: 0.07, // Reduced opacity
// child: ClipOval(
// child: Image.asset(
// 'assets/images/logo.png',
// width: 200, // Adjust size as needed
// height: 200, // Adjust size as needed
// ),
// ),
// ),
// ),
// ),
// ],
// ),
// );
// }
@override
Widget build(BuildContext context) {
final loc = AppLocalizations.of(context);
return Scaffold(
appBar: AppBar(
title: Text(loc.profile),
elevation: 0,
),
body: Stack(
children: [
ListView(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
children: [
// ===== Profile Header =====
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 8,
offset: const Offset(0, 4),
),
],
),
ListTile(
leading: const Icon(Icons.security),
title: Text(loc.securitySettings),
trailing: const Icon(Icons.chevron_right),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SecuritySettingsScreen(
mobileNumber: widget.mobileNumber,
child: Row(
children: [
// Avatar
Container(
width: 56,
height: 56,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey.shade200,
image: const DecorationImage(
image: AssetImage('assets/images/logo.png'),
fit: BoxFit.cover,
),
),
);
},
),
const SizedBox(width: 12),
// Name + mobile
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
// If you want to show the user's name instead, replace below.
widget.customerName,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 4),
Text(
widget.customerNo,
style: TextStyle(
fontSize: 14,
color: Colors.grey.shade600,
),
),
],
),
),
// Edit/Profile button (optional)
TextButton.icon(
onPressed: () {
// TODO: Navigate to edit profile if required
},
icon: const Icon(Icons.edit, size: 18),
label: const Text("Edit"),
style: TextButton.styleFrom(
foregroundColor: Colors.blueGrey.shade700,
),
),
],
),
ListTile(
leading: const Icon(Icons.currency_rupee),
title: Text(AppLocalizations.of(context).dailylimit),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const DailyLimitScreen()),
);
},
),
const SizedBox(height: 16),
// ===== Section: Settings =====
const Text(
"Settings",
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
letterSpacing: 0.2,
),
SwitchListTile(
title:
Text(AppLocalizations.of(context).enableFingerprintLogin),
),
const SizedBox(height: 8),
_SectionTile(
leadingIcon: Icons.settings,
title: loc.preferences,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const PreferenceScreen(),
),
);
},
),
_SectionTile(
leadingIcon: Icons.security,
title: loc.securitySettings,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SecuritySettingsScreen(
mobileNumber: widget.mobileNumber,
),
),
);
},
),
_SectionTile(
leadingIcon: Icons.currency_rupee,
title: loc.dailylimit,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const DailyLimitScreen(),
),
);
},
),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 8,
offset: const Offset(0, 4),
),
],
),
child: SwitchListTile(
title: Text(loc.enableFingerprintLogin),
value: _isBiometricEnabled,
onChanged: (bool value) {
// The state is now managed within _handleBiometricToggle
_handleBiometricToggle(value);
},
secondary: const Icon(Icons.fingerprint),
contentPadding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
),
ListTile(
),
const SizedBox(height: 16),
const Divider(height: 24),
// ===== Section: Security & App =====
Text(
loc.appVersion,
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
letterSpacing: 0.2,
),
),
const SizedBox(height: 8),
// Fingerprint toggle inside a styled container
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 8,
offset: const Offset(0, 4),
),
],
),
child: ListTile(
leading: const Icon(Icons.smartphone),
title: const Text("App Version"),
title: Text(loc.appVersion),
trailing: FutureBuilder<String>(
future: _getAppVersion(),
builder:
(BuildContext context, AsyncSnapshot<String> snapshot) {
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
// Show a loading indicator while waiting for the future to complete
return const CircularProgressIndicator();
return const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
);
} else if (snapshot.hasError) {
return const Text("Error");
return Text(loc.error);
} else {
// Display the version number once the future is complete
return Text(
snapshot.data ?? "N/A",
selectionColor: const Color(0xFFFFFFFF),
@@ -238,69 +512,141 @@ class _ProfileScreenState extends State<ProfileScreen> {
}
},
),
contentPadding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
),
ListTile(
leading: const Icon(Icons.exit_to_app),
title: Text(AppLocalizations.of(context).logout),
onTap: () async {
final shouldExit = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text(AppLocalizations.of(context).logout),
content: Text(AppLocalizations.of(context).logoutCheck),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text(AppLocalizations.of(context).no),
),
TextButton(
onPressed: () => Navigator.of(context).pop(true),
child: Text(AppLocalizations.of(context).yes),
),
],
),
);
),
if (shouldExit == true) {
if (Platform.isAndroid) {
SystemNavigator.pop();
}
exit(0);
}
},
),
ListTile(
leading: const Icon(Icons.logout),
title: Text(AppLocalizations.of(context).deregister),
onTap: () async {
final shouldLogout = await showDialog<bool>(
context: context,
builder: (_) => const LogoutDialog(),
);
const SizedBox(height: 16),
const Divider(height: 24),
if (shouldLogout == true) {
await _handleLogout(context);
}
},
// ===== Section: Actions =====
const Text(
"Exit",
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
letterSpacing: 0.2,
),
],
),
IgnorePointer(
),
const SizedBox(height: 8),
_SectionTile(
leadingIcon: Icons.exit_to_app,
title: loc.logout,
trailChevron: false, // action tile, no chevron
onTap: () async {
final shouldExit = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text(loc.logout),
content: Text(loc.logoutCheck),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text(loc.no),
),
TextButton(
onPressed: () => Navigator.of(context).pop(true),
child: Text(loc.yes),
),
],
),
);
if (shouldExit == true) {
if (Platform.isAndroid) {
SystemNavigator.pop();
}
exit(0);
}
},
),
_SectionTile(
leadingIcon: Icons.logout,
title: loc.deregister,
trailChevron: false,
onTap: () async {
final shouldLogout = await showDialog<bool>(
context: context,
builder: (_) => const LogoutDialog(),
);
if (shouldLogout == true) {
await _handleLogout(context);
}
},
),
const SizedBox(height: 24),
],
),
// ===== Watermark (kept subtle, no theme change) =====
IgnorePointer(
child: Positioned.fill(
child: Center(
child: Opacity(
opacity: 0.07, // Reduced opacity
opacity: 0.06,
child: ClipOval(
child: Image.asset(
'assets/images/logo.png',
width: 200, // Adjust size as needed
height: 200, // Adjust size as needed
width: 200,
height: 200,
filterQuality: FilterQuality.medium,
),
),
),
),
),
),
],
),
);
}
}
class _SectionTile extends StatelessWidget {
const _SectionTile({
required this.leadingIcon,
required this.title,
this.onTap,
this.trailChevron = true,
});
final IconData leadingIcon;
final String title;
final VoidCallback? onTap;
final bool trailChevron;
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 8,
offset: const Offset(0, 4),
),
],
),
child: ListTile(
leading: Icon(leadingIcon),
title: Text(title),
trailing: trailChevron ? const Icon(Icons.chevron_right) : null,
onTap: onTap,
contentPadding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
),
);
}
}