471 lines
15 KiB
Dart
471 lines
15 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import '../../core/services/auth_service.dart';
|
|
import '../../core/services/notification_service.dart';
|
|
import '../../core/services/chit_group_service.dart';
|
|
import '../../core/utils/snackbar_util.dart';
|
|
import '../../shared/widgets/interactive_card.dart';
|
|
import '../../shared/widgets/notification_badge.dart';
|
|
import '../../features/notifications/notification_center_page.dart';
|
|
import 'member_group_details_page.dart';
|
|
|
|
class MemberDashboard extends StatefulWidget {
|
|
const MemberDashboard({super.key});
|
|
|
|
@override
|
|
State<MemberDashboard> createState() => _MemberDashboardState();
|
|
}
|
|
|
|
class _MemberDashboardState extends State<MemberDashboard> {
|
|
final _chitGroupService = Get.find<ChitGroupService>();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// Initialize notification service
|
|
if (!Get.isRegistered<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(
|
|
backgroundColor: Colors.grey.shade50,
|
|
appBar: AppBar(
|
|
title: Text(
|
|
'My Chitfunds',
|
|
style: TextStyle(
|
|
fontSize: 18.sp,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
backgroundColor: Colors.green.shade600,
|
|
foregroundColor: Colors.white,
|
|
elevation: 2,
|
|
actions: [
|
|
// Notifications with badge
|
|
Obx(() {
|
|
final unreadCount = NotificationService.to.unreadCount.value;
|
|
return IconButton(
|
|
icon: NotificationBadge(
|
|
count: unreadCount,
|
|
child: Icon(Icons.notifications_rounded, size: 24.w),
|
|
),
|
|
onPressed: () => Get.to(() => const NotificationCenterPage()),
|
|
tooltip: 'Notifications',
|
|
);
|
|
}),
|
|
IconButton(
|
|
icon: Icon(Icons.logout, size: 24.w),
|
|
onPressed: () => _showLogoutDialog(context),
|
|
),
|
|
],
|
|
),
|
|
body: Obx(() {
|
|
final groups = _chitGroupService.chitGroups;
|
|
final isLoading = _chitGroupService.isLoading.value;
|
|
|
|
return RefreshIndicator(
|
|
onRefresh: _loadData,
|
|
child: ListView(
|
|
padding: EdgeInsets.all(12.w),
|
|
children: [
|
|
// Welcome Section
|
|
Container(
|
|
padding: EdgeInsets.all(20.w),
|
|
decoration: BoxDecoration(
|
|
gradient: LinearGradient(
|
|
colors: [Colors.green.shade50, Colors.green.shade100],
|
|
),
|
|
borderRadius: BorderRadius.circular(16.r),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.green.shade200.withOpacity(0.3),
|
|
blurRadius: 8,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
CircleAvatar(
|
|
radius: 24.r,
|
|
backgroundColor: Colors.green.shade600,
|
|
child: Icon(
|
|
Icons.person,
|
|
size: 24.w,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
SizedBox(width: 12.w),
|
|
Expanded(
|
|
child: Text(
|
|
'Welcome, ${AuthService.to.currentUser.value?.fullName ?? 'Member'}!',
|
|
style: TextStyle(
|
|
fontSize: 20.sp,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.green.shade800,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 12.h),
|
|
Text(
|
|
groups.isEmpty
|
|
? 'Join a chit fund to start managing your investments.'
|
|
: 'Manage your chit fund investments and track your payments.',
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
color: Colors.green.shade700,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(height: 16.h),
|
|
|
|
// Loading indicator
|
|
if (isLoading)
|
|
Center(
|
|
child: Padding(
|
|
padding: EdgeInsets.all(32.h),
|
|
child: CircularProgressIndicator(
|
|
color: Colors.green.shade600,
|
|
),
|
|
),
|
|
),
|
|
|
|
// Empty state
|
|
if (!isLoading && groups.isEmpty)
|
|
_buildEmptyState(),
|
|
|
|
// My Chitfunds Section (only if groups exist)
|
|
if (!isLoading && groups.isNotEmpty) ...[
|
|
Text(
|
|
'My Chitfunds',
|
|
style: TextStyle(
|
|
fontSize: 20.sp,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.grey.shade800,
|
|
),
|
|
),
|
|
SizedBox(height: 12.h),
|
|
...groups.map((group) => Padding(
|
|
padding: EdgeInsets.only(bottom: 12.h),
|
|
child: _buildGroupCard(group),
|
|
)),
|
|
],
|
|
|
|
SizedBox(height: 16.h),
|
|
],
|
|
),
|
|
);
|
|
}),
|
|
bottomNavigationBar: Obx(() {
|
|
final unreadCount = NotificationService.to.unreadCount.value;
|
|
|
|
return BottomNavigationBar(
|
|
type: BottomNavigationBarType.fixed,
|
|
selectedItemColor: Colors.green.shade600,
|
|
unselectedItemColor: Colors.grey.shade600,
|
|
selectedLabelStyle: TextStyle(fontSize: 12.sp, fontWeight: FontWeight.w600),
|
|
unselectedLabelStyle: TextStyle(fontSize: 12.sp),
|
|
iconSize: 24.w,
|
|
items: [
|
|
const BottomNavigationBarItem(
|
|
icon: Icon(Icons.home),
|
|
label: 'Home',
|
|
),
|
|
const BottomNavigationBarItem(
|
|
icon: Icon(Icons.payment),
|
|
label: 'Payments',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: NotificationBadge(
|
|
count: unreadCount,
|
|
child: const Icon(Icons.notifications),
|
|
),
|
|
label: 'Notifications',
|
|
),
|
|
const BottomNavigationBarItem(
|
|
icon: Icon(Icons.person),
|
|
label: 'Profile',
|
|
),
|
|
],
|
|
onTap: (index) {
|
|
if (index == 2) {
|
|
Get.to(() => const NotificationCenterPage());
|
|
} else {
|
|
SnackbarUtil.showInfo('Feature coming soon');
|
|
}
|
|
},
|
|
);
|
|
}),
|
|
);
|
|
}
|
|
|
|
Widget _buildEmptyState() {
|
|
return Center(
|
|
child: Padding(
|
|
padding: EdgeInsets.all(32.w),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
Icons.account_balance_wallet_outlined,
|
|
size: 80.w,
|
|
color: Colors.grey.shade300,
|
|
),
|
|
SizedBox(height: 24.h),
|
|
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(
|
|
color: Colors.blue.shade50,
|
|
borderRadius: BorderRadius.circular(12.r),
|
|
border: Border.all(color: Colors.blue.shade200),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Icon(
|
|
Icons.info_outline,
|
|
color: Colors.blue.shade700,
|
|
size: 20.w,
|
|
),
|
|
SizedBox(width: 8.w),
|
|
Text(
|
|
'How to get started?',
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.blue.shade700,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 12.h),
|
|
Text(
|
|
'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(
|
|
fontSize: 14.sp,
|
|
color: Colors.blue.shade900,
|
|
height: 1.5,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildGroupCard(dynamic group) {
|
|
final color = Colors.green.shade600;
|
|
final groupName = group.name ?? 'Unnamed Group';
|
|
final totalValue = group.totalValue ?? 0.0;
|
|
final monthlyInstallment = group.monthlyInstallment ?? 0.0;
|
|
final durationMonths = group.durationMonths ?? 0;
|
|
final status = group.status ?? 'pending';
|
|
|
|
// Format currency
|
|
final totalValueFormatted = '₹${_formatCurrency(totalValue)}';
|
|
final installmentValueFormatted = '₹${_formatCurrency(monthlyInstallment)}';
|
|
|
|
return InteractiveCard(
|
|
onTap: () {
|
|
Get.to(() => MemberGroupDetailsPage(group: group));
|
|
},
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
groupName,
|
|
style: TextStyle(
|
|
fontSize: 20.sp,
|
|
fontWeight: FontWeight.bold,
|
|
color: color,
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
SizedBox(width: 8.w),
|
|
Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 6.h),
|
|
decoration: BoxDecoration(
|
|
color: _getStatusColor(status).withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(16.r),
|
|
border: Border.all(color: _getStatusColor(status), width: 1.5),
|
|
),
|
|
child: Text(
|
|
_getStatusText(status),
|
|
style: TextStyle(
|
|
fontSize: 14.sp,
|
|
color: _getStatusColor(status),
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 16.h),
|
|
Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: _buildGroupInfo('Total Value', totalValueFormatted),
|
|
),
|
|
SizedBox(width: 8.w),
|
|
Expanded(
|
|
child: _buildGroupInfo('Duration', '$durationMonths months'),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 12.h),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: _buildGroupInfo('Installment', installmentValueFormatted),
|
|
),
|
|
SizedBox(width: 8.w),
|
|
Expanded(
|
|
child: _buildGroupInfo('Status', _getStatusText(status)),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
String _formatCurrency(double amount) {
|
|
// Format number with Indian comma notation
|
|
final amountStr = amount.toStringAsFixed(0);
|
|
return amountStr.replaceAllMapped(
|
|
RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'),
|
|
(Match m) => '${m[1]},'
|
|
);
|
|
}
|
|
|
|
Widget _buildGroupInfo(String label, String value) {
|
|
return Container(
|
|
padding: EdgeInsets.all(12.w),
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey.shade50,
|
|
borderRadius: BorderRadius.circular(12.r),
|
|
border: Border.all(color: Colors.grey.shade200),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
label,
|
|
style: TextStyle(
|
|
fontSize: 14.sp,
|
|
color: Colors.grey.shade600,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
SizedBox(height: 6.h),
|
|
Text(
|
|
value,
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w600,
|
|
color: Colors.grey.shade800,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
|
|
void _showLogoutDialog(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('Logout'),
|
|
content: const Text('Are you sure you want to logout?'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('Cancel'),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
AuthService.to.logout();
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.red,
|
|
foregroundColor: Colors.white,
|
|
),
|
|
child: const Text('Logout'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|