member dashboard update

This commit is contained in:
Deep Koluguri 2025-11-05 21:06:44 -05:00
parent 43d41f04c7
commit f985c00545
1 changed files with 221 additions and 252 deletions

View File

@ -3,21 +3,39 @@ import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../core/services/auth_service.dart'; import '../../core/services/auth_service.dart';
import '../../core/services/notification_service.dart'; import '../../core/services/notification_service.dart';
import '../../core/services/chit_group_service.dart';
import '../../core/utils/snackbar_util.dart'; import '../../core/utils/snackbar_util.dart';
import '../../shared/widgets/interactive_card.dart'; import '../../shared/widgets/interactive_card.dart';
import '../../shared/widgets/notification_badge.dart'; import '../../shared/widgets/notification_badge.dart';
import '../../features/notifications/notification_center_page.dart'; import '../../features/notifications/notification_center_page.dart';
class MemberDashboard extends StatelessWidget { class MemberDashboard extends StatefulWidget {
const MemberDashboard({super.key}); const MemberDashboard({super.key});
@override @override
Widget build(BuildContext context) { State<MemberDashboard> createState() => _MemberDashboardState();
}
class _MemberDashboardState extends State<MemberDashboard> {
final _chitGroupService = Get.find<ChitGroupService>();
@override
void initState() {
super.initState();
// Initialize notification service // Initialize notification service
if (!Get.isRegistered<NotificationService>()) { if (!Get.isRegistered<NotificationService>()) {
Get.put(NotificationService()); Get.put(NotificationService());
} }
// Load member's chit groups
_loadData();
}
Future<void> _loadData() async {
await _chitGroupService.loadMemberChitGroups(status: 'active');
}
@override
Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: Colors.grey.shade50, backgroundColor: Colors.grey.shade50,
appBar: AppBar( appBar: AppBar(
@ -50,11 +68,12 @@ class MemberDashboard extends StatelessWidget {
), ),
], ],
), ),
body: RefreshIndicator( body: Obx(() {
onRefresh: () async { final groups = _chitGroupService.chitGroups;
// TODO: Implement refresh logic final isLoading = _chitGroupService.isLoading.value;
await Future.delayed(const Duration(seconds: 1));
}, return RefreshIndicator(
onRefresh: _loadData,
child: ListView( child: ListView(
padding: EdgeInsets.all(12.w), padding: EdgeInsets.all(12.w),
children: [ children: [
@ -90,20 +109,22 @@ class MemberDashboard extends StatelessWidget {
), ),
SizedBox(width: 12.w), SizedBox(width: 12.w),
Expanded( Expanded(
child: Obx(() => Text( child: Text(
'Welcome, ${AuthService.to.currentUser.value?.fullName ?? 'Member'}!', 'Welcome, ${AuthService.to.currentUser.value?.fullName ?? 'Member'}!',
style: TextStyle( style: TextStyle(
fontSize: 20.sp, fontSize: 20.sp,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: Colors.green.shade800, color: Colors.green.shade800,
), ),
)), ),
), ),
], ],
), ),
SizedBox(height: 12.h), SizedBox(height: 12.h),
Text( Text(
'Manage your chit fund investments and track your payments.', groups.isEmpty
? 'Join a chit fund to start managing your investments.'
: 'Manage your chit fund investments and track your payments.',
style: TextStyle( style: TextStyle(
fontSize: 16.sp, fontSize: 16.sp,
color: Colors.green.shade700, color: Colors.green.shade700,
@ -114,11 +135,23 @@ class MemberDashboard extends StatelessWidget {
), ),
SizedBox(height: 16.h), SizedBox(height: 16.h),
// Payment Due Card // Loading indicator
_buildPaymentDueCard(), if (isLoading)
SizedBox(height: 16.h), Center(
child: Padding(
padding: EdgeInsets.all(32.h),
child: CircularProgressIndicator(
color: Colors.green.shade600,
),
),
),
// My Chitfunds Section // Empty state
if (!isLoading && groups.isEmpty)
_buildEmptyState(),
// My Chitfunds Section (only if groups exist)
if (!isLoading && groups.isNotEmpty) ...[
Text( Text(
'My Chitfunds', 'My Chitfunds',
style: TextStyle( style: TextStyle(
@ -128,62 +161,17 @@ class MemberDashboard extends StatelessWidget {
), ),
), ),
SizedBox(height: 12.h), SizedBox(height: 12.h),
_buildGroupCard( ...groups.map((group) => Padding(
'Group A', padding: EdgeInsets.only(bottom: 12.h),
'₹1,00,000', child: _buildGroupCard(group),
'20 months', )),
'15/20 members', ],
'₹5,000',
'Due: 25th Jan',
Colors.blue,
),
SizedBox(height: 12.h),
_buildGroupCard(
'Group B',
'₹50,000',
'10 months',
'8/10 members',
'₹5,000',
'Due: 28th Jan',
Colors.green,
),
SizedBox(height: 16.h),
// Recent Activity Section
Text(
'Recent Activity',
style: TextStyle(
fontSize: 20.sp,
fontWeight: FontWeight.bold,
color: Colors.grey.shade800,
),
),
SizedBox(height: 12.h),
ActivityCard(
title: 'Payment Successful',
description: '₹5,000 paid for Group A',
time: '2h ago',
icon: Icons.payment,
color: Colors.green.shade600,
),
ActivityCard(
title: 'Lottery Draw',
description: 'Draw completed for Group B',
time: '1d ago',
icon: Icons.casino,
color: Colors.orange.shade600,
),
ActivityCard(
title: 'New Member',
description: 'John Doe joined Group A',
time: '3d ago',
icon: Icons.person_add,
color: Colors.blue.shade600,
),
SizedBox(height: 16.h), SizedBox(height: 16.h),
], ],
), ),
), );
}),
bottomNavigationBar: Obx(() { bottomNavigationBar: Obx(() {
final unreadCount = NotificationService.to.unreadCount.value; final unreadCount = NotificationService.to.unreadCount.value;
@ -227,93 +215,77 @@ class MemberDashboard extends StatelessWidget {
); );
} }
Widget _buildPaymentDueCard() { Widget _buildEmptyState() {
return Card( return Center(
elevation: 3, child: Padding(
shape: RoundedRectangleBorder( padding: EdgeInsets.all(32.w),
borderRadius: BorderRadius.circular(16.r), child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.account_balance_wallet_outlined,
size: 80.w,
color: Colors.grey.shade300,
), ),
child: Container( SizedBox(height: 24.h),
padding: EdgeInsets.all(20.w), Text(
'No Chit Funds Yet',
style: TextStyle(
fontSize: 22.sp,
fontWeight: FontWeight.bold,
color: Colors.grey.shade700,
),
),
SizedBox(height: 12.h),
Text(
'You haven\'t joined any chit funds yet.\nContact your manager to get started!',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16.sp,
color: Colors.grey.shade600,
),
),
SizedBox(height: 32.h),
Container(
padding: EdgeInsets.all(16.w),
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: LinearGradient( color: Colors.blue.shade50,
colors: [Colors.orange.shade50, Colors.orange.shade100], borderRadius: BorderRadius.circular(12.r),
), border: Border.all(color: Colors.blue.shade200),
borderRadius: BorderRadius.circular(16.r),
), ),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row( Row(
children: [ children: [
Container( Icon(
padding: EdgeInsets.all(8.w), Icons.info_outline,
decoration: BoxDecoration( color: Colors.blue.shade700,
color: Colors.orange.shade600.withOpacity(0.1), size: 20.w,
borderRadius: BorderRadius.circular(12.r),
), ),
child: Icon( SizedBox(width: 8.w),
Icons.payment,
color: Colors.orange.shade700,
size: 28.w,
),
),
SizedBox(width: 12.w),
Text( Text(
'Payment Due', 'How to get started?',
style: TextStyle( style: TextStyle(
fontSize: 18.sp, fontSize: 16.sp,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: Colors.orange.shade700, color: Colors.blue.shade700,
), ),
), ),
], ],
), ),
SizedBox(height: 16.h), SizedBox(height: 12.h),
Text( Text(
'₹5,000', '1. Your manager will add you to a chit group\n'
'2. You\'ll receive a notification\n'
'3. Start managing your payments here!',
style: TextStyle( style: TextStyle(
fontSize: 28.sp, fontSize: 14.sp,
fontWeight: FontWeight.bold, color: Colors.blue.shade900,
color: Colors.orange.shade800, height: 1.5,
),
),
SizedBox(height: 6.h),
Text(
'Due by 25th January 2024',
style: TextStyle(
fontSize: 16.sp,
color: Colors.orange.shade700,
fontWeight: FontWeight.w500,
),
),
SizedBox(height: 20.h),
SizedBox(
width: double.infinity,
height: 48.h,
child: ElevatedButton(
onPressed: () {
// TODO: Implement payment
SnackbarUtil.showInfo(
'Payment feature coming soon!',
title: 'Coming Soon',
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.orange.shade600,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.r),
),
elevation: 2,
),
child: Text(
'Pay Now',
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
), ),
), ),
],
), ),
), ),
], ],
@ -322,15 +294,18 @@ class MemberDashboard extends StatelessWidget {
); );
} }
Widget _buildGroupCard( Widget _buildGroupCard(dynamic group) {
String name, final color = Colors.green.shade600;
String value, final groupName = group.name ?? 'Unnamed Group';
String duration, final totalAmount = group.totalAmount ?? 0;
String members, final monthlyInstallment = group.monthlyInstallment ?? 0;
String installment, final durationMonths = group.durationMonths ?? 0;
String dueDate, final status = group.status ?? 'pending';
Color color,
) { // Format currency
final totalValue = '${totalAmount.toString().replaceAllMapped(RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'), (Match m) => '${m[1]},')}';
final installmentValue = '${monthlyInstallment.toString().replaceAllMapped(RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'), (Match m) => '${m[1]},')}';
return InteractiveCard( return InteractiveCard(
onTap: () { onTap: () {
SnackbarUtil.showInfo('Group details page coming soon!'); SnackbarUtil.showInfo('Group details page coming soon!');
@ -341,26 +316,31 @@ class MemberDashboard extends StatelessWidget {
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Expanded(
name, child: Text(
groupName,
style: TextStyle( style: TextStyle(
fontSize: 20.sp, fontSize: 20.sp,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: color, color: color,
), ),
maxLines: 1,
overflow: TextOverflow.ellipsis,
), ),
),
SizedBox(width: 8.w),
Container( Container(
padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 6.h), padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 6.h),
decoration: BoxDecoration( decoration: BoxDecoration(
color: color.withOpacity(0.1), color: _getStatusColor(status).withOpacity(0.1),
borderRadius: BorderRadius.circular(16.r), borderRadius: BorderRadius.circular(16.r),
border: Border.all(color: color, width: 1.5), border: Border.all(color: _getStatusColor(status), width: 1.5),
), ),
child: Text( child: Text(
'Active', _getStatusText(status),
style: TextStyle( style: TextStyle(
fontSize: 14.sp, fontSize: 14.sp,
color: color, color: _getStatusColor(status),
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
), ),
), ),
@ -373,11 +353,11 @@ class MemberDashboard extends StatelessWidget {
Row( Row(
children: [ children: [
Expanded( Expanded(
child: _buildGroupInfo('Total Value', value), child: _buildGroupInfo('Total Value', totalValue),
), ),
SizedBox(width: 8.w), SizedBox(width: 8.w),
Expanded( Expanded(
child: _buildGroupInfo('Duration', duration), child: _buildGroupInfo('Duration', '$durationMonths months'),
), ),
], ],
), ),
@ -385,49 +365,38 @@ class MemberDashboard extends StatelessWidget {
Row( Row(
children: [ children: [
Expanded( Expanded(
child: _buildGroupInfo('Members', members), child: _buildGroupInfo('Installment', installmentValue),
), ),
SizedBox(width: 8.w), SizedBox(width: 8.w),
Expanded( Expanded(
child: _buildGroupInfo('Installment', installment), child: _buildGroupInfo('Status', _getStatusText(status)),
), ),
], ],
), ),
], ],
), ),
SizedBox(height: 16.h),
Container(
width: double.infinity,
padding: EdgeInsets.all(12.w),
decoration: BoxDecoration(
color: color.withOpacity(0.05),
borderRadius: BorderRadius.circular(12.r),
border: Border.all(color: color.withOpacity(0.3)),
),
child: Row(
children: [
Icon(
Icons.schedule,
size: 20.w,
color: color,
),
SizedBox(width: 8.w),
Text(
dueDate,
style: TextStyle(
fontSize: 16.sp,
color: color,
fontWeight: FontWeight.w600,
),
),
],
),
),
], ],
), ),
); );
} }
Color _getStatusColor(String status) {
switch (status.toLowerCase()) {
case 'active':
return Colors.green.shade600;
case 'pending':
return Colors.orange.shade600;
case 'completed':
return Colors.blue.shade600;
default:
return Colors.grey.shade600;
}
}
String _getStatusText(String status) {
return status[0].toUpperCase() + status.substring(1).toLowerCase();
}
Widget _buildGroupInfo(String label, String value) { Widget _buildGroupInfo(String label, String value) {
return Container( return Container(
padding: EdgeInsets.all(12.w), padding: EdgeInsets.all(12.w),