Revamp stage one - individual account and account setup fixed

This commit is contained in:
2026-08-25 19:45:24 +05:30
parent 82c1a891c0
commit 53c1f62373
52 changed files with 3980 additions and 4020 deletions

View File

@@ -25,6 +25,40 @@ class ProfileScreen extends ConsumerStatefulWidget {
class _ProfileScreenState extends ConsumerState<ProfileScreen> {
bool _isExporting = false;
String? _profileType;
String _userName = 'Loading...';
String _userEmail = 'Loading...';
@override
void initState() {
super.initState();
_fetchProfileType();
}
Future<void> _fetchProfileType() async {
try {
final res = await DioClient().dio.get('/account/setup/status');
if (mounted) {
setState(() {
_profileType = res.data['profileType'];
_userName = res.data['name'] ?? 'Kifi User';
if (_userName.isEmpty) _userName = 'Kifi User';
_userEmail = res.data['email'] ?? '';
});
}
} catch (e) {
// ignore
}
}
String _getInitials(String name) {
if (name.isEmpty || name == 'Kifi User' || name == 'Loading...') return 'U';
final parts = name.trim().split(' ');
if (parts.length > 1 && parts[1].isNotEmpty) {
return '${parts[0][0]}${parts[1][0]}'.toUpperCase();
}
return name.substring(0, name.length >= 2 ? 2 : 1).toUpperCase();
}
Future<void> _logout(BuildContext context) async {
const storage = FlutterSecureStorage();
@@ -63,131 +97,211 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
appBar: AppBar(
title: const Text('Profile'),
title: Text('Profile', style: Theme.of(context).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold)),
backgroundColor: Colors.transparent,
elevation: 0,
centerTitle: true,
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(height: 20),
CircleAvatar(
radius: 50,
backgroundColor: Theme.of(context).colorScheme.primary.withOpacity(0.1),
child: Icon(LucideIcons.user, size: 50, color: Theme.of(context).colorScheme.primary),
),
const SizedBox(height: 24),
const Text('Kifi User', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
const SizedBox(height: 8),
const Text('maddy23285@gmail.com', style: TextStyle(color: Colors.grey, fontSize: 16)),
const SizedBox(height: 48),
Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Column(
children: [
ListTile(
leading: const Icon(LucideIcons.downloadCloud),
title: const Text('Export Data to CSV'),
trailing: _isExporting
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2))
: const Icon(LucideIcons.chevronRight),
onTap: _isExporting ? null : _exportData,
),
const Divider(height: 1),
ListTile(
leading: const Icon(LucideIcons.moon),
title: const Text('Theme'),
trailing: SegmentedButton<ThemeMode>(
segments: const [
ButtonSegment(value: ThemeMode.light, icon: Icon(LucideIcons.sun)),
ButtonSegment(value: ThemeMode.system, icon: Icon(LucideIcons.monitor)),
ButtonSegment(value: ThemeMode.dark, icon: Icon(LucideIcons.moon)),
],
selected: {ref.watch(themeProvider)},
onSelectionChanged: (Set<ThemeMode> newSelection) {
ref.read(themeProvider.notifier).setTheme(newSelection.first);
},
showSelectedIcon: false,
style: ButtonStyle(visualDensity: VisualDensity.compact),
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 600),
child: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 20),
Center(
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: Theme.of(context).primaryColor.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Center(
child: Text(
_getInitials(_userName),
style: TextStyle(
fontSize: 36,
fontWeight: FontWeight.bold,
color: Theme.of(context).primaryColor,
),
),
),
),
const Divider(height: 1),
Consumer(
builder: (context, ref, child) {
final isBusinessMode = ref.watch(businessModeProvider);
return Column(
children: [
SwitchListTile(
secondary: const Icon(LucideIcons.briefcase),
title: const Text('Business Mode'),
subtitle: const Text('Inventory and sales management'),
value: isBusinessMode,
onChanged: (val) {
ref.read(businessModeProvider.notifier).toggleMode();
},
),
if (isBusinessMode) ...[
const Divider(height: 1),
ListTile(
leading: const Icon(LucideIcons.settings),
title: const Text('Business Settings'),
subtitle: const Text('Tax, Modules, POS'),
trailing: const Icon(LucideIcons.chevronRight),
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (_) => const BusinessSettingsScreen()));
},
),
],
const Divider(height: 1),
Consumer(
builder: (context, ref, child) {
final isProjectMode = ref.watch(projectModeProvider);
return SwitchListTile(
secondary: const Icon(LucideIcons.trello),
title: const Text('Project Management (Agency OS)'),
subtitle: const Text('Task boards and billable hours'),
value: isProjectMode,
onChanged: (val) {
ref.read(projectModeProvider.notifier).toggleMode();
},
);
},
)
],
);
}
),
const Divider(height: 1),
ListTile(
leading: const Icon(LucideIcons.helpCircle),
title: const Text('Help & Support'),
trailing: const Icon(LucideIcons.chevronRight),
onTap: () {},
),
const SizedBox(height: 24),
Text(
_userName,
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold, color: Theme.of(context).textTheme.bodyLarge?.color),
textAlign: TextAlign.center,
),
if (_userEmail.isNotEmpty) ...[
const SizedBox(height: 8),
Text(
_userEmail,
style: TextStyle(color: isDark ? Colors.grey.shade400 : Colors.grey.shade600, fontSize: 16),
textAlign: TextAlign.center,
),
],
),
),
const Spacer(),
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: () => _logout(context),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red.withOpacity(0.1),
foregroundColor: Colors.red,
padding: const EdgeInsets.symmetric(vertical: 16),
const SizedBox(height: 48),
Container(
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(color: Colors.black.withOpacity(isDark ? 0.2 : 0.02), blurRadius: 10, offset: const Offset(0, 4)),
],
border: Border.all(color: Theme.of(context).dividerColor.withOpacity(isDark ? 0.1 : 0.2)),
),
child: Column(
children: [
ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 4),
leading: Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(color: Colors.blue.shade50, borderRadius: BorderRadius.circular(10)),
child: Icon(LucideIcons.downloadCloud, color: Colors.blue.shade600, size: 22),
),
title: const Text('Export Data to CSV', style: TextStyle(fontWeight: FontWeight.w600)),
trailing: _isExporting
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2))
: const Icon(LucideIcons.chevronRight, size: 20),
onTap: _isExporting ? null : _exportData,
),
Divider(height: 1, indent: 64, color: Theme.of(context).dividerColor.withOpacity(isDark ? 0.1 : 0.05)),
ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 4),
leading: Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(color: Colors.purple.shade50, borderRadius: BorderRadius.circular(10)),
child: Icon(LucideIcons.moon, color: Colors.purple.shade600, size: 22),
),
title: const Text('Theme', style: TextStyle(fontWeight: FontWeight.w600)),
trailing: SegmentedButton<ThemeMode>(
segments: const [
ButtonSegment(value: ThemeMode.light, icon: Icon(LucideIcons.sun, size: 18)),
ButtonSegment(value: ThemeMode.system, icon: Icon(LucideIcons.monitor, size: 18)),
ButtonSegment(value: ThemeMode.dark, icon: Icon(LucideIcons.moon, size: 18)),
],
selected: {ref.watch(themeProvider)},
onSelectionChanged: (Set<ThemeMode> newSelection) {
ref.read(themeProvider.notifier).setTheme(newSelection.first);
},
showSelectedIcon: false,
style: ButtonStyle(
visualDensity: VisualDensity.compact,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
),
),
Divider(height: 1, indent: 64, color: Theme.of(context).dividerColor.withOpacity(isDark ? 0.1 : 0.05)),
Consumer(
builder: (context, ref, child) {
final isBusinessMode = ref.watch(businessModeProvider);
return Column(
children: [
if (_profileType == 'BUSINESS') ...[
SwitchListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 4),
secondary: Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(color: Colors.orange.shade50, borderRadius: BorderRadius.circular(10)),
child: Icon(LucideIcons.briefcase, color: Colors.orange.shade600, size: 22),
),
title: const Text('Business Mode', style: TextStyle(fontWeight: FontWeight.w600)),
subtitle: Text('Inventory and sales', style: TextStyle(fontSize: 12, color: Colors.grey.shade600)),
value: isBusinessMode,
activeColor: Theme.of(context).primaryColor,
onChanged: (val) {
ref.read(businessModeProvider.notifier).toggleMode();
},
),
if (isBusinessMode) ...[
Divider(height: 1, indent: 64, color: Theme.of(context).dividerColor.withOpacity(isDark ? 0.1 : 0.05)),
ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 4),
leading: Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(color: Colors.grey.shade100, borderRadius: BorderRadius.circular(10)),
child: Icon(LucideIcons.settings, color: Colors.grey.shade700, size: 22),
),
title: const Text('Business Settings', style: TextStyle(fontWeight: FontWeight.w600)),
subtitle: Text('Tax, Modules, POS', style: TextStyle(fontSize: 12, color: Colors.grey.shade600)),
trailing: const Icon(LucideIcons.chevronRight, size: 20),
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (_) => const BusinessSettingsScreen()));
},
),
],
Divider(height: 1, indent: 64, color: Theme.of(context).dividerColor.withOpacity(isDark ? 0.1 : 0.05)),
Consumer(
builder: (context, ref, child) {
final isProjectMode = ref.watch(projectModeProvider);
return SwitchListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 4),
secondary: Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(color: Colors.teal.shade50, borderRadius: BorderRadius.circular(10)),
child: Icon(LucideIcons.trello, color: Colors.teal.shade600, size: 22),
),
title: const Text('Project Management', style: TextStyle(fontWeight: FontWeight.w600)),
subtitle: Text('Task boards and tracking', style: TextStyle(fontSize: 12, color: Colors.grey.shade600)),
value: isProjectMode,
activeColor: Theme.of(context).primaryColor,
onChanged: (val) {
ref.read(projectModeProvider.notifier).toggleMode();
},
);
},
),
Divider(height: 1, indent: 64, color: Theme.of(context).dividerColor.withOpacity(isDark ? 0.1 : 0.05)),
],
],
);
}
),
ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 4),
leading: Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(color: Colors.green.shade50, borderRadius: BorderRadius.circular(10)),
child: Icon(LucideIcons.helpCircle, color: Colors.green.shade600, size: 22),
),
title: const Text('Help & Support', style: TextStyle(fontWeight: FontWeight.w600)),
trailing: const Icon(LucideIcons.chevronRight, size: 20),
onTap: () {},
),
],
),
),
icon: const Icon(LucideIcons.logOut),
label: const Text('Log Out', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
),
const SizedBox(height: 48),
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: () => _logout(context),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red.withOpacity(0.08),
foregroundColor: Colors.red.shade700,
elevation: 0,
padding: const EdgeInsets.symmetric(vertical: 20),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
),
icon: const Icon(LucideIcons.logOut, size: 22),
label: const Text('Log Out', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, letterSpacing: 0.5)),
),
),
const SizedBox(height: 20),
],
),
const SizedBox(height: 20),
],
),
),
),
),