UI_FILTER

This commit is contained in:
venbaittech 2025-10-09 09:22:34 +05:30
parent af081f73b3
commit 88e65c0923
7 changed files with 1124 additions and 652 deletions

View File

@ -609,7 +609,12 @@ class ApiService {
// ----------------------------------- POLICY ------------------------------------------------- // ----------------------------------- POLICY -------------------------------------------------
Future<Map<String, dynamic>> fetchPolicyList(int id, role) async { Future<Map<String, dynamic>> fetchPolicyList(
int id,
role, {
String? fromDate,
String? toDate,
}) async {
// print(_token); // print(_token);
if (_token == null) { if (_token == null) {
await _initializeToken(); await _initializeToken();
@ -618,11 +623,25 @@ class ApiService {
final userId = '1'; final userId = '1';
final url; final url;
final String query;
if (role == 'manager') { if (role == 'manager') {
url = Uri.parse('${Env.apiUrl}enquiry/enquiryList?manager_id=$id'); query = 'manager_id=$id';
} else if (role == 'staff') {
query = 'staff_id=$id';
} else { } else {
url = Uri.parse('${Env.apiUrl}enquiry/enquiryList?staff_id=$id'); query = 'agent_id=$id';
} }
url = Uri.parse(
'${Env.apiUrl}enquiry/enquiryList?$query&from_date=${fromDate ?? ''}&to_date=${toDate ?? ''}',
);
// if (role == 'manager') {
// url = Uri.parse('${Env.apiUrl}enquiry/enquiryList?manager_id=$id');
// } else {
// url = Uri.parse('${Env.apiUrl}enquiry/enquiryList?staff_id=$id');
// }
// else { // else {
// url = Uri.parse('${Env.apiUrl}endorsement/endorsementList?agent_id=$id'); // url = Uri.parse('${Env.apiUrl}endorsement/endorsementList?agent_id=$id');
// } // }
@ -637,28 +656,47 @@ class ApiService {
return response; return response;
} }
Future<Map<String, dynamic>> fetchPolicyDataOnlyList(int id, role) async { Future<Map<String, dynamic>> fetchPolicyDataOnlyList(
int id,
role, {
String? fromDate,
String? toDate,
}) async {
// print(_token); // print(_token);
if (_token == null) { if (_token == null) {
await _initializeToken(); await _initializeToken();
} }
final userId = '1'; final userId = '1';
final url;
final String query;
if (role == 'manager') { if (role == 'manager') {
url = Uri.parse( query = 'manager_id=$id';
'${Env.apiUrl}enquiry/enquiryList?manager_id=$id&only_policy_data=true',
);
} else if (role == 'staff') { } else if (role == 'staff') {
url = Uri.parse( query = 'staff_id=$id';
'${Env.apiUrl}enquiry/enquiryList?staff_id=$id&only_policy_data=true',
);
} else { } else {
url = Uri.parse( query = 'agent_id=$id';
'${Env.apiUrl}enquiry/enquiryList?agent_id=$id&only_policy_data=true',
);
} }
final url = Uri.parse(
'${Env.apiUrl}enquiry/enquiryList?$query&only_policy_data=true&from_date=${fromDate ?? ''}&to_date=${toDate ?? ''}',
);
// if (role == 'manager') {
// url = Uri.parse(
// '${Env.apiUrl}enquiry/enquiryList?manager_id=$id&only_policy_data=true',
// );
// } else if (role == 'staff') {
// url = Uri.parse(
// '${Env.apiUrl}enquiry/enquiryList?staff_id=$id&only_policy_data=true',
// );
// } else {
// url = Uri.parse(
// '${Env.apiUrl}enquiry/enquiryList?agent_id=$id&only_policy_data=true',
// );
// }
// final url = Uri.parse( // final url = Uri.parse(
// 'https://venbait.in/nhance/partner/dev/api/agent/agentList?manager_id=${managerId}', // 'https://venbait.in/nhance/partner/dev/api/agent/agentList?manager_id=${managerId}',
// ); // );

View File

@ -27,9 +27,9 @@ class MainLayout extends StatelessWidget {
appBar: TopBar( appBar: TopBar(
title: title, title: title,
isMobile: true, isMobile: true,
onBack: () { // onBack: () {
// Navigator.pop(context); // // Navigator.pop(context);
}, // },
onNotifications: () { onNotifications: () {
debugPrint("Notifications tapped"); debugPrint("Notifications tapped");
}, },

View File

@ -38,9 +38,9 @@ class EnquiryListState extends ConsumerState<EnquiryList> {
List<Map<String, dynamic>> getStaffData = []; List<Map<String, dynamic>> getStaffData = [];
List<Map<String, dynamic>> originalData = []; List<Map<String, dynamic>> originalData = [];
List<Map<String, dynamic>> filteredData = []; List<Map<String, dynamic>> filteredData = [];
Map<String, TextEditingController> controllers = {};
bool isLoading = false;
bool isLoading = false;
Map<String, TextEditingController> controllers = {};
List<String> tabHeader = ['startDate', 'endDate']; List<String> tabHeader = ['startDate', 'endDate'];
@override @override
@ -378,15 +378,55 @@ class EnquiryListState extends ConsumerState<EnquiryList> {
), ),
SizedBox(height: ResponsiveLayout.isMobile(context) ? 5 : 10), SizedBox(height: ResponsiveLayout.isMobile(context) ? 5 : 10),
ResponsiveLayout.isMobile(context)
Expanded( ? Container(
height: MediaQuery.of(context).size.height * 0.7,
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(8),
child: _buildContent(context),
),
),
)
: Expanded(
child: Container( child: Container(
// color: Colors.green,
// color: Colors.green.shade50,
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
padding: EdgeInsets.all(8.0), padding: EdgeInsets.all(8.0),
child: Column( child: _buildContent(context),
),
),
Container(
// height: 20,
width: MediaQuery.of(context).size.width,
// color: Colors.green.shade50,
child: PaginationControls(
currentPage: currentPage,
itemsPerPage: itemsPerPage,
// totalItems: dataVal.length,
totalItems: filteredData.length,
// activeColor: layoutColor, // your theme color
onPageChanged: (page) {
setState(() {
currentPage = page;
});
},
onItemsPerPageChanged: (items) {
setState(() {
itemsPerPage = items;
currentPage = 1;
});
},
),
),
],
),
),
);
}
Widget _buildContent(BuildContext context) {
return Column(
children: [ children: [
if (ResponsiveLayout.isMobile(context)) ...[ if (ResponsiveLayout.isMobile(context)) ...[
Container( Container(
@ -486,9 +526,7 @@ class EnquiryListState extends ConsumerState<EnquiryList> {
sheetName: "Enquiry", sheetName: "Enquiry",
fileName: "enquiry_list", fileName: "enquiry_list",
data: filteredData, data: filteredData,
txt: !ResponsiveLayout.isMobile(context) txt: !ResponsiveLayout.isMobile(context) ? true : false,
? true
: false,
headers: [ headers: [
"id", "id",
"created_on", "created_on",
@ -503,8 +541,7 @@ class EnquiryListState extends ConsumerState<EnquiryList> {
SizedBox(width: 10), SizedBox(width: 10),
GestureDetector( GestureDetector(
onTap: () async { onTap: () async {
final prefs = final prefs = await SharedPreferences.getInstance();
await SharedPreferences.getInstance();
await prefs.remove('enqAgentDataId'); await prefs.remove('enqAgentDataId');
context.go(AppRoutes.tabEnquiry); context.go(AppRoutes.tabEnquiry);
@ -524,7 +561,7 @@ class EnquiryListState extends ConsumerState<EnquiryList> {
if (!ResponsiveLayout.isMobile(context)) ...[ if (!ResponsiveLayout.isMobile(context)) ...[
SizedBox(width: 10), SizedBox(width: 10),
Text( Text(
'Create New Enquiry', 'Raise Enquiry',
style: GoogleFonts.inter( style: GoogleFonts.inter(
color: Colors.white, color: Colors.white,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
@ -566,16 +603,10 @@ class EnquiryListState extends ConsumerState<EnquiryList> {
color: Color(0xFFEDF6F5), color: Color(0xFFEDF6F5),
borderRadius: BorderRadius.circular(6), borderRadius: BorderRadius.circular(6),
), ),
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
vertical: 12,
horizontal: 16,
),
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(flex: 1, child: Text('S.No.', style: _headerStyle)),
flex: 1,
child: Text('S.No.', style: _headerStyle),
),
Expanded( Expanded(
flex: 2, flex: 2,
child: Text('Created Date', style: _headerStyle), child: Text('Created Date', style: _headerStyle),
@ -584,64 +615,53 @@ class EnquiryListState extends ConsumerState<EnquiryList> {
flex: 2, flex: 2,
child: Text('Updated Date', style: _headerStyle), child: Text('Updated Date', style: _headerStyle),
), ),
Expanded( Expanded(flex: 1, child: Text('Reg.No.', style: _headerStyle)),
flex: 1, Expanded(flex: 3, child: Text('Company', style: _headerStyle)),
child: Text('Reg.No.', style: _headerStyle), Expanded(flex: 2, child: Text('Status', style: _headerStyle)),
), Expanded(flex: 2, child: Text('Remarks', style: _headerStyle)),
Expanded( Expanded(flex: 1, child: Text('Action', style: _headerStyle)),
flex: 3,
child: Text('Company', style: _headerStyle),
),
Expanded(
flex: 2,
child: Text('Status', style: _headerStyle),
),
Expanded(
flex: 2,
child: Text('Remarks', style: _headerStyle),
),
Expanded(
flex: 1,
child: Text('Action', style: _headerStyle),
),
], ],
), ),
), ),
Expanded(child: _buildDataTable(context)),
],
),
),
),
Container( ResponsiveLayout.isMobile(context)
// height: 20, ? _buildDataTable(context)
width: MediaQuery.of(context).size.width, : Expanded(child: _buildDataTable(context)),
// color: Colors.green.shade50,
child: PaginationControls(
currentPage: currentPage,
itemsPerPage: itemsPerPage,
// totalItems: dataVal.length,
totalItems: filteredData.length,
// activeColor: layoutColor, // your theme color
onPageChanged: (page) {
setState(() {
currentPage = page;
});
},
onItemsPerPageChanged: (items) {
setState(() {
itemsPerPage = items;
currentPage = 1;
});
},
),
),
], ],
),
),
); );
} }
// Widget _buildDataTable1(BuildContext context) {
// if (filteredData.isEmpty) {
// return const SizedBox(
// height: 50,
// child: Center(child: Text('No available data')),
// );
// }
//
// final sortedData = [..._paginatedData];
// return ListView.builder(
// itemCount: ResponsiveLayout.isMobile(context)
// ? sortedData
// .length // only cards for mobile
// : sortedData.length + 1, // +1 for header in desktop
// itemBuilder: (context, index) {
// if (!ResponsiveLayout.isMobile(context) && index == 0) {
// return _buildHeader();
// }
//
// final startIndex = (currentPage - 1) * itemsPerPage;
// final item =
// sortedData[index - (ResponsiveLayout.isMobile(context) ? 0 : 1)];
// final sno = startIndex + index;
//
// return !ResponsiveLayout.isMobile(context)
// ? _buildDataRow(item, sno)
// : _buildDataCard(item, sno);
// },
// );
// }
Widget _buildDataTable(BuildContext context) { Widget _buildDataTable(BuildContext context) {
if (filteredData.isEmpty) { if (filteredData.isEmpty) {
return const SizedBox( return const SizedBox(
@ -651,24 +671,28 @@ class EnquiryListState extends ConsumerState<EnquiryList> {
} }
final sortedData = [..._paginatedData]; final sortedData = [..._paginatedData];
return ListView.builder(
itemCount: ResponsiveLayout.isMobile(context) if (ResponsiveLayout.isMobile(context)) {
? sortedData // Use Column instead of ListView
.length // only cards for mobile return Column(
: sortedData.length + 1, // +1 for header in desktop children: List.generate(sortedData.length, (index) {
itemBuilder: (context, index) { final startIndex = (currentPage - 1) * itemsPerPage;
if (!ResponsiveLayout.isMobile(context) && index == 0) { final item = sortedData[index];
return _buildHeader(); final sno = startIndex + index;
return _buildDataCard(item, sno);
}),
);
} }
// Desktop: keep ListView.builder
return ListView.builder(
itemCount: sortedData.length + 1,
itemBuilder: (context, index) {
if (index == 0) return _buildHeader();
final startIndex = (currentPage - 1) * itemsPerPage; final startIndex = (currentPage - 1) * itemsPerPage;
final item = final item = sortedData[index - 1];
sortedData[index - (ResponsiveLayout.isMobile(context) ? 0 : 1)];
final sno = startIndex + index; final sno = startIndex + index;
return _buildDataRow(item, sno);
return !ResponsiveLayout.isMobile(context)
? _buildDataRow(item, sno)
: _buildDataCard(item, sno);
}, },
); );
} }

View File

@ -37,6 +37,7 @@ import '../../../themes/indicators/text_field_theme.dart';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import '../../../widgets/custom_Stdate_EnDate_Filter.dart';
import '../../../widgets/custom_action_popup.dart'; import '../../../widgets/custom_action_popup.dart';
import '../assignStaff.dart'; import '../assignStaff.dart';
@ -50,6 +51,8 @@ class EnquiryStaffState extends ConsumerState<EnquiryStaff> {
int currentPage = 1; int currentPage = 1;
int itemsPerPage = 10; int itemsPerPage = 10;
late ApiService apiService; late ApiService apiService;
dynamic userId;
final _formKey = GlobalKey<FormState>();
// List<Map<String, dynamic>> dataVal = []; // List<Map<String, dynamic>> dataVal = [];
List<Map<String, dynamic>> getStaffData = []; List<Map<String, dynamic>> getStaffData = [];
@ -58,19 +61,28 @@ class EnquiryStaffState extends ConsumerState<EnquiryStaff> {
bool isLoading = false; bool isLoading = false;
dynamic roleId; dynamic roleId;
Map<String, TextEditingController> controllers = {};
List<String> tabHeader = ['startDate', 'endDate'];
@override @override
void initState() { void initState() {
super.initState(); super.initState();
apiService = ApiService(); apiService = ApiService();
for (String field in tabHeader) {
controllers[field] = TextEditingController();
}
Future.microtask(() { Future.microtask(() {
final id = ref.read(managerIdProvider); final id = ref.read(managerIdProvider);
roleId = ref.read(userRoleProvider); roleId = ref.read(userRoleProvider);
final userId = ref.read(userIdProvider); userId = ref.read(userIdProvider);
print("C72 => r : $roleId | mId: $id | uId: $userId "); print("C72 => r : $roleId | mId: $id | uId: $userId ");
if (userId != null) { getStaffList(userId, roleId); } if (userId != null) {
getStaffList(userId, roleId);
}
}); });
} }
@ -80,24 +92,84 @@ class EnquiryStaffState extends ConsumerState<EnquiryStaff> {
final userId = ref.read(userIdProvider); final userId = ref.read(userIdProvider);
print("C82 => r : $roleId | mId: $id | uId: $userId "); print("C82 => r : $roleId | mId: $id | uId: $userId ");
if (userId != null) { getStaffList(userId, roleId); } if (userId != null) {
getStaffList(userId, roleId);
}
} }
Future<void> getStaffList(int managerId, role) async { void filterDateRange() {
// Validate the form first
if (!_formKey.currentState!.validate()) {
// stop execution if validation fails
return;
}
final fromDateText = controllers['startDate']?.text ?? '';
final toDateText = controllers['endDate']?.text ?? '';
// Optional: double-check End >= Start
final fromDate = DateFormat('dd-MM-yyyy').parse(fromDateText);
final toDate = DateFormat('dd-MM-yyyy').parse(toDateText);
if (toDate.isBefore(fromDate)) {
// This is already caught by the validator, but extra safety
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("End Date cannot be earlier than Start Date")),
);
return;
}
// Call your API
getStaffList(userId, roleId);
}
void refrshfilterDateRange() {
setState(() {
controllers['startDate']!.clear();
controllers['endDate']!.clear();
controllers['startDate']?.text = '';
controllers['endDate']?.text = '';
// Reset the FormField validation
_formKey.currentState?.reset();
});
getStaffList(userId, roleId);
}
Future<void> getStaffList(
int managerId,
role, {
String fromDate = '',
String toDate = '',
}) async {
print('C89 => Fns called => $managerId | $role'); print('C89 => Fns called => $managerId | $role');
setState(() { setState(() {
isLoading = true; isLoading = true;
}); });
try { try {
final response = await apiService.fetchPolicyList(managerId, role); final response = await apiService.fetchPolicyList(
managerId,
role,
fromDate: controllers['startDate']?.text ?? '',
toDate: controllers['endDate']?.text ?? '',
);
print('FromDate : $fromDate');
print('ToDate : $toDate');
if (response['status'] == 'success') { if (response['status'] == 'success') {
final data = response['data']; final data = response['data'];
print('C99 => getStaffListData => ${response['data']}'); print('C99 => getStaffListData => ${response['data']}');
final fromDate = response['from_date'] ?? '';
final toDate = response['to_date'] ?? '';
print('FromDate : $fromDate');
print('ToDate : $toDate');
setState(() { setState(() {
controllers['startDate']?.text = fromDate;
controllers['endDate']?.text = toDate;
if (data is List) { if (data is List) {
// Already a list of maps // Already a list of maps
getStaffData = List<Map<String, dynamic>>.from(data); getStaffData = List<Map<String, dynamic>>.from(data);
@ -391,16 +463,87 @@ class EnquiryStaffState extends ConsumerState<EnquiryStaff> {
), ),
SizedBox(height: 10), SizedBox(height: 10),
ResponsiveLayout.isMobile(context)
Expanded( ? Container(
height: MediaQuery.of(context).size.height * 0.69,
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(8),
child: _buildContent(context),
),
),
)
: Expanded(
child: Container( child: Container(
// color: Colors.green,
// color: Colors.green.shade50,
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
padding: EdgeInsets.all(8.0), padding: EdgeInsets.all(8.0),
child: Column( child: _buildContent(context),
),
),
// Expanded(
// child: Container(
// // color: Colors.green,
// // color: Colors.green.shade50,
// width: MediaQuery.of(context).size.width,
//
// padding: EdgeInsets.all(8.0),
// child:
// ),
// ),
Container(
// height: 20,
width: MediaQuery.of(context).size.width,
// color: Colors.green.shade50,
child: PaginationControls(
currentPage: currentPage,
itemsPerPage: itemsPerPage,
// totalItems: dataVal.length,
totalItems: filteredData.length,
// activeColor: layoutColor, // your theme color
onPageChanged: (page) {
setState(() {
currentPage = page;
});
},
onItemsPerPageChanged: (items) {
setState(() {
itemsPerPage = items;
currentPage = 1;
});
},
),
),
],
),
),
);
}
Widget _buildContent(BuildContext context) {
return Column(
children: [ children: [
if (ResponsiveLayout.isMobile(context)) ...[
Container(
padding: EdgeInsets.all(8.0),
color: Color(0xffD9EBE8),
child: DateFilterRow(
startController: controllers['startDate']!,
endController: controllers['endDate']!,
formKey: _formKey,
isMobile: ResponsiveLayout.isMobile(context),
onFilter: () {
// call your filter logic
filterDateRange();
},
onRefresh: () {
// call your refresh logic
refrshfilterDateRange();
},
),
),
],
Container( Container(
// height: 40, // height: 40,
// color: Colors.pink, // color: Colors.pink,
@ -408,25 +551,80 @@ class EnquiryStaffState extends ConsumerState<EnquiryStaff> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
if (!ResponsiveLayout.isMobile(context)) ...[
DateFilterRow(
startController: controllers['startDate']!,
endController: controllers['endDate']!,
formKey: _formKey,
isMobile: ResponsiveLayout.isMobile(context),
onFilter: () {
// call your filter logic
filterDateRange();
},
onRefresh: () {
// call your refresh logic
refrshfilterDateRange();
},
),
// Form(
// key: _formKey,
// child: Row(
// mainAxisAlignment: MainAxisAlignment.start,
// crossAxisAlignment: CrossAxisAlignment.end,
// children: [
// buildStartDate(context),
// SizedBox(width: 10),
// buildEndDate(context),
// SizedBox(width: 10),
//
// Padding(
// padding: const EdgeInsets.symmetric(
// vertical: 8.0,
// ),
// child: GestureDetector(
// // onTap: filterDateRange,
// onTap: () {
// if (_formKey.currentState!.validate()) {
// filterDateRange(); // only runs if valid
// }
// },
// child: Icon(Icons.filter_alt_outlined),
// ),
// ),
//
// Padding(
// padding: const EdgeInsets.all(8.0),
// child: GestureDetector(
// onTap: refrshfilterDateRange,
// child: Icon(Icons.refresh),
// ),
// ),
// ],
// ),
// ),
Spacer(),
],
ThemedSearchField( ThemedSearchField(
hintText: 'Search', hintText: 'Search',
backgroundColor: Color(0xFFF6F8F8), backgroundColor: Color(0xFFF6F8F8),
onChanged: filterData, onChanged: filterData,
controller: _searchStaffController, controller: _searchStaffController,
txtwidth: ResponsiveLayout.isMobile(context) txtwidth: ResponsiveLayout.isMobile(context)
? MediaQuery.of(context).size.width * 0.6 ? MediaQuery.of(context).size.width * 0.7
: MediaQuery.of(context).size.width * 0.2, : MediaQuery.of(context).size.width * 0.2,
), ),
Spacer(), ResponsiveLayout.isMobile(context)
? Spacer()
: SizedBox(width: 10),
ExportBtn( ExportBtn(
sheetName: "Enquiry", sheetName: "Enquiry",
fileName: "Enquiry_list", fileName: "Enquiry_list",
data: filteredData, data: filteredData,
txt: !ResponsiveLayout.isMobile(context) txt: !ResponsiveLayout.isMobile(context) ? true : false,
? true
: false,
headers: [ headers: [
"created_on", "created_on",
"updated_on", "updated_on",
@ -490,10 +688,7 @@ class EnquiryStaffState extends ConsumerState<EnquiryStaff> {
color: Color(0xFFEDF6F5), color: Color(0xFFEDF6F5),
borderRadius: BorderRadius.circular(6), borderRadius: BorderRadius.circular(6),
), ),
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
vertical: 12,
horizontal: 16,
),
child: const Row( child: const Row(
children: [ children: [
Expanded( Expanded(
@ -504,36 +699,21 @@ class EnquiryStaffState extends ConsumerState<EnquiryStaff> {
flex: 3, flex: 3,
child: Text('Updated Date', style: _headerStyle), child: Text('Updated Date', style: _headerStyle),
), ),
Expanded( Expanded(flex: 2, child: Text('Reg.No', style: _headerStyle)),
flex: 2, Expanded(flex: 2, child: Text('Agents', style: _headerStyle)),
child: Text('Reg.No', style: _headerStyle),
),
Expanded(
flex: 2,
child: Text('Agents', style: _headerStyle),
),
Expanded( Expanded(
flex: 2, flex: 2,
child: Text('Assigned To', style: _headerStyle), child: Text('Assigned To', style: _headerStyle),
), ),
Expanded( Expanded(flex: 3, child: Text('Insurer', style: _headerStyle)),
flex: 3,
child: Text('Insurer', style: _headerStyle),
),
Expanded( Expanded(
flex: 3, flex: 3,
child: Padding( child: Padding(
padding: EdgeInsets.only(left: 8.0), padding: EdgeInsets.only(left: 8.0),
child: Text( child: Text('Insured Name', style: _headerStyle),
'Insured Name',
style: _headerStyle,
), ),
), ),
), Expanded(flex: 2, child: Text('Premium', style: _headerStyle)),
Expanded(
flex: 2,
child: Text('Premium', style: _headerStyle),
),
Expanded( Expanded(
flex: 2, flex: 2,
child: Text('Payment Mode', style: _headerStyle), child: Text('Payment Mode', style: _headerStyle),
@ -543,49 +723,15 @@ class EnquiryStaffState extends ConsumerState<EnquiryStaff> {
child: Text('Policy Number', style: _headerStyle), child: Text('Policy Number', style: _headerStyle),
), ),
Expanded( Expanded(flex: 3, child: Text('Status', style: _headerStyle)),
flex: 3, Expanded(flex: 1, child: Text('Action', style: _headerStyle)),
child: Text('Status', style: _headerStyle),
),
Expanded(
flex: 1,
child: Text('Action', style: _headerStyle),
),
], ],
), ),
), ),
Expanded(child: _buildDataTable(context)), ResponsiveLayout.isMobile(context)
? _buildDataTable(context)
: Expanded(child: _buildDataTable(context)),
], ],
),
),
),
Container(
// height: 20,
width: MediaQuery.of(context).size.width,
// color: Colors.green.shade50,
child: PaginationControls(
currentPage: currentPage,
itemsPerPage: itemsPerPage,
// totalItems: dataVal.length,
totalItems: filteredData.length,
// activeColor: layoutColor, // your theme color
onPageChanged: (page) {
setState(() {
currentPage = page;
});
},
onItemsPerPageChanged: (items) {
setState(() {
itemsPerPage = items;
currentPage = 1;
});
},
),
),
],
),
),
); );
} }
@ -598,28 +744,63 @@ class EnquiryStaffState extends ConsumerState<EnquiryStaff> {
} }
final sortedData = [..._paginatedData]; final sortedData = [..._paginatedData];
return ListView.builder(
itemCount: ResponsiveLayout.isMobile(context) if (ResponsiveLayout.isMobile(context)) {
? sortedData // Use Column instead of ListView
.length // only cards for mobile return Column(
: sortedData.length + 1, // +1 for header in desktop children: List.generate(sortedData.length, (index) {
itemBuilder: (context, index) { final startIndex = (currentPage - 1) * itemsPerPage;
if (!ResponsiveLayout.isMobile(context) && index == 0) { final item = sortedData[index];
return _buildHeader(); final sno = startIndex + index;
return _buildDataCard(item, sno);
}),
);
} }
// Desktop: keep ListView.builder
return ListView.builder(
itemCount: sortedData.length + 1,
itemBuilder: (context, index) {
if (index == 0) return _buildHeader();
final startIndex = (currentPage - 1) * itemsPerPage; final startIndex = (currentPage - 1) * itemsPerPage;
final item = final item = sortedData[index - 1];
sortedData[index - (ResponsiveLayout.isMobile(context) ? 0 : 1)];
final sno = startIndex + index; final sno = startIndex + index;
return _buildDataRow(item, sno);
return !ResponsiveLayout.isMobile(context)
? _buildDataRow(item, sno)
: _buildDataCard(item, sno);
}, },
); );
} }
// Widget _buildDataTable(BuildContext context) {
// if (filteredData.isEmpty) {
// return const SizedBox(
// height: 50,
// child: Center(child: Text('No available data')),
// );
// }
//
// final sortedData = [..._paginatedData];
// return ListView.builder(
// itemCount: ResponsiveLayout.isMobile(context)
// ? sortedData
// .length // only cards for mobile
// : sortedData.length + 1, // +1 for header in desktop
// itemBuilder: (context, index) {
// if (!ResponsiveLayout.isMobile(context) && index == 0) {
// return _buildHeader();
// }
//
// final startIndex = (currentPage - 1) * itemsPerPage;
// final item =
// sortedData[index - (ResponsiveLayout.isMobile(context) ? 0 : 1)];
// final sno = startIndex + index;
//
// return !ResponsiveLayout.isMobile(context)
// ? _buildDataRow(item, sno)
// : _buildDataCard(item, sno);
// },
// );
// }
Widget _buildHeader() { Widget _buildHeader() {
return SizedBox.shrink(); return SizedBox.shrink();
} }

View File

@ -15,6 +15,7 @@ import '../../../providers/manager_provider.dart';
import '../../../providers/quotation_staff_proivder.dart'; import '../../../providers/quotation_staff_proivder.dart';
import '../../../themes/indicators/export_btn.dart'; import '../../../themes/indicators/export_btn.dart';
import '../../../themes/indicators/search_field_theme.dart'; import '../../../themes/indicators/search_field_theme.dart';
import '../../../widgets/custom_Stdate_EnDate_Filter.dart';
import '../../../widgets/custom_action_popup.dart'; import '../../../widgets/custom_action_popup.dart';
class policylist extends ConsumerStatefulWidget { class policylist extends ConsumerStatefulWidget {
@ -27,13 +28,16 @@ class policylistState extends ConsumerState<policylist> {
int currentPage = 1; int currentPage = 1;
int itemsPerPage = 10; int itemsPerPage = 10;
late ApiService apiService; late ApiService apiService;
dynamic userId;
// List<Map<String, dynamic>> dataVal = []; // List<Map<String, dynamic>> dataVal = [];
List<Map<String, dynamic>> getStaffData = []; List<Map<String, dynamic>> getStaffData = [];
List<Map<String, dynamic>> originalData = []; List<Map<String, dynamic>> originalData = [];
List<Map<String, dynamic>> filteredData = []; List<Map<String, dynamic>> filteredData = [];
bool isLoading = false; bool isLoading = false;
dynamic roleId; dynamic roleId;
final _formKey = GlobalKey<FormState>();
Map<String, TextEditingController> controllers = {};
List<String> tabHeader = ['startDate', 'endDate'];
@override @override
void initState() { void initState() {
@ -41,10 +45,14 @@ class policylistState extends ConsumerState<policylist> {
apiService = ApiService(); apiService = ApiService();
for (String field in tabHeader) {
controllers[field] = TextEditingController();
}
Future.microtask(() { Future.microtask(() {
final id = ref.read(managerIdProvider); final id = ref.read(managerIdProvider);
roleId = ref.read(userRoleProvider); roleId = ref.read(userRoleProvider);
final userId = ref.read(userIdProvider); userId = ref.read(userIdProvider);
print("D49 => r : $roleId | mId: $id | uId: $userId "); print("D49 => r : $roleId | mId: $id | uId: $userId ");
if (userId != null) { if (userId != null) {
@ -64,7 +72,12 @@ class policylistState extends ConsumerState<policylist> {
} }
} }
Future<void> getStaffList(int managerId, role) async { Future<void> getStaffList(
int managerId,
role, {
String fromDate = '',
String toDate = '',
}) async {
print('D68 => Fns called => $managerId | $role'); print('D68 => Fns called => $managerId | $role');
setState(() { setState(() {
isLoading = true; isLoading = true;
@ -74,12 +87,22 @@ class policylistState extends ConsumerState<policylist> {
final response = await apiService.fetchPolicyDataOnlyList( final response = await apiService.fetchPolicyDataOnlyList(
managerId, managerId,
role, role,
fromDate: controllers['startDate']?.text ?? '',
toDate: controllers['endDate']?.text ?? '',
); );
if (response['status'] == 'success') { if (response['status'] == 'success') {
final data = response['data']; final data = response['data'];
print('D81 => getStaffListData => ${response['data']}'); print('D81 => getStaffListData => ${response['data']}');
final fromDate = response['from_date'] ?? '';
final toDate = response['to_date'] ?? '';
print('FromDate : $fromDate');
print('ToDate : $toDate');
setState(() { setState(() {
controllers['startDate']?.text = fromDate;
controllers['endDate']?.text = toDate;
if (data is List) { if (data is List) {
// Already a list of maps // Already a list of maps
getStaffData = List<Map<String, dynamic>>.from(data); getStaffData = List<Map<String, dynamic>>.from(data);
@ -124,6 +147,45 @@ class policylistState extends ConsumerState<policylist> {
return sortedData.sublist(startIndex, endIndex); return sortedData.sublist(startIndex, endIndex);
} }
void filterDateRange() {
// Validate the form first
if (!_formKey.currentState!.validate()) {
// stop execution if validation fails
return;
}
final fromDateText = controllers['startDate']?.text ?? '';
final toDateText = controllers['endDate']?.text ?? '';
// Optional: double-check End >= Start
final fromDate = DateFormat('dd-MM-yyyy').parse(fromDateText);
final toDate = DateFormat('dd-MM-yyyy').parse(toDateText);
if (toDate.isBefore(fromDate)) {
// This is already caught by the validator, but extra safety
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("End Date cannot be earlier than Start Date")),
);
return;
}
// Call your API
getStaffList(userId, roleId);
}
void refrshfilterDateRange() {
setState(() {
controllers['startDate']!.clear();
controllers['endDate']!.clear();
controllers['startDate']?.text = '';
controllers['endDate']?.text = '';
// Reset the FormField validation
_formKey.currentState?.reset();
});
getStaffList(userId, roleId);
}
void filterData(String query) { void filterData(String query) {
print("FilterDAta - $query"); print("FilterDAta - $query");
setState(() { setState(() {
@ -334,15 +396,77 @@ class policylistState extends ConsumerState<policylist> {
SizedBox(height: 10), SizedBox(height: 10),
Expanded( ResponsiveLayout.isMobile(context)
? Container(
height: MediaQuery.of(context).size.height * 0.69,
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(8),
child: _buildContent(context),
),
),
)
: Expanded(
child: Container( child: Container(
// color: Colors.green,
// color: Colors.green.shade50,
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
padding: EdgeInsets.all(8.0), padding: EdgeInsets.all(8.0),
child: Column( child: _buildContent(context),
),
),
Container(
// height: 20,
width: MediaQuery.of(context).size.width,
// color: Colors.green.shade50,
child: PaginationControls(
currentPage: currentPage,
itemsPerPage: itemsPerPage,
// totalItems: dataVal.length,
totalItems: filteredData.length,
// activeColor: layoutColor, // your theme color
onPageChanged: (page) {
setState(() {
currentPage = page;
});
},
onItemsPerPageChanged: (items) {
setState(() {
itemsPerPage = items;
currentPage = 1;
});
},
),
),
],
),
),
);
}
Widget _buildContent(BuildContext context) {
return Column(
children: [ children: [
if (ResponsiveLayout.isMobile(context)) ...[
Container(
padding: EdgeInsets.all(8.0),
color: Color(0xffD9EBE8),
child: DateFilterRow(
startController: controllers['startDate']!,
endController: controllers['endDate']!,
formKey: _formKey,
isMobile: ResponsiveLayout.isMobile(context),
onFilter: () {
// call your filter logic
filterDateRange();
},
onRefresh: () {
// call your refresh logic
refrshfilterDateRange();
},
),
),
],
Container( Container(
// height: 40, // height: 40,
// color: Colors.pink, // color: Colors.pink,
@ -350,25 +474,80 @@ class policylistState extends ConsumerState<policylist> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
if (!ResponsiveLayout.isMobile(context)) ...[
DateFilterRow(
startController: controllers['startDate']!,
endController: controllers['endDate']!,
formKey: _formKey,
isMobile: ResponsiveLayout.isMobile(context),
onFilter: () {
// call your filter logic
filterDateRange();
},
onRefresh: () {
// call your refresh logic
refrshfilterDateRange();
},
),
// Form(
// key: _formKey,
// child: Row(
// mainAxisAlignment: MainAxisAlignment.start,
// crossAxisAlignment: CrossAxisAlignment.end,
// children: [
// buildStartDate(context),
// SizedBox(width: 10),
// buildEndDate(context),
// SizedBox(width: 10),
//
// Padding(
// padding: const EdgeInsets.symmetric(
// vertical: 8.0,
// ),
// child: GestureDetector(
// // onTap: filterDateRange,
// onTap: () {
// if (_formKey.currentState!.validate()) {
// filterDateRange(); // only runs if valid
// }
// },
// child: Icon(Icons.filter_alt_outlined),
// ),
// ),
//
// Padding(
// padding: const EdgeInsets.all(8.0),
// child: GestureDetector(
// onTap: refrshfilterDateRange,
// child: Icon(Icons.refresh),
// ),
// ),
// ],
// ),
// ),
Spacer(),
],
ResponsiveLayout.isMobile(context)
? SizedBox(height: 10)
: SizedBox.shrink(),
ThemedSearchField( ThemedSearchField(
hintText: 'Search', hintText: 'Search',
backgroundColor: Color(0xFFF6F8F8), backgroundColor: Color(0xFFF6F8F8),
onChanged: filterData, onChanged: filterData,
controller: _searchStaffController, controller: _searchStaffController,
txtwidth: ResponsiveLayout.isMobile(context) txtwidth: ResponsiveLayout.isMobile(context)
? MediaQuery.of(context).size.width * 0.6 ? MediaQuery.of(context).size.width * 0.7
: MediaQuery.of(context).size.width * 0.2, : MediaQuery.of(context).size.width * 0.2,
), ),
ResponsiveLayout.isMobile(context)
Spacer(), ? Spacer()
: SizedBox(width: 10),
ExportBtn( ExportBtn(
sheetName: "Policy", sheetName: "Policy",
fileName: "Policy_list", fileName: "Policy_list",
data: filteredData, data: filteredData,
txt: !ResponsiveLayout.isMobile(context) txt: !ResponsiveLayout.isMobile(context) ? true : false,
? true
: false,
headers: [ headers: [
"reg_no", "reg_no",
"agent_name", "agent_name",
@ -430,40 +609,22 @@ class policylistState extends ConsumerState<policylist> {
color: Color(0xFFEDF6F5), color: Color(0xFFEDF6F5),
borderRadius: BorderRadius.circular(6), borderRadius: BorderRadius.circular(6),
), ),
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
vertical: 12,
horizontal: 16,
),
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(flex: 4, child: Text('Date', style: _headerStyle)),
flex: 4, Expanded(flex: 3, child: Text('Reg.No', style: _headerStyle)),
child: Text('Date', style: _headerStyle), Expanded(flex: 3, child: Text('Agents', style: _headerStyle)),
),
Expanded(
flex: 3,
child: Text('Reg.No', style: _headerStyle),
),
Expanded(
flex: 3,
child: Text('Agents', style: _headerStyle),
),
Expanded( Expanded(
flex: 3, flex: 3,
child: Text('Assigned To', style: _headerStyle), child: Text('Assigned To', style: _headerStyle),
), ),
Expanded( Expanded(flex: 3, child: Text('Insurer', style: _headerStyle)),
flex: 3,
child: Text('Insurer', style: _headerStyle),
),
Expanded( Expanded(
flex: 3, flex: 3,
child: Text('Insured Name', style: _headerStyle), child: Text('Insured Name', style: _headerStyle),
), ),
Expanded( Expanded(flex: 3, child: Text('Premium', style: _headerStyle)),
flex: 3,
child: Text('Premium', style: _headerStyle),
),
Expanded( Expanded(
flex: 3, flex: 3,
child: Text('Payment Mode', style: _headerStyle), child: Text('Payment Mode', style: _headerStyle),
@ -480,41 +641,46 @@ class policylistState extends ConsumerState<policylist> {
], ],
), ),
), ),
Expanded(child: _buildDataTable(context)),
],
),
),
),
Container( // Expanded(child: _buildDataTable(context)),
// height: 20, ResponsiveLayout.isMobile(context)
width: MediaQuery.of(context).size.width, ? _buildDataTable(context)
// color: Colors.green.shade50, : Expanded(child: _buildDataTable(context)),
child: PaginationControls(
currentPage: currentPage,
itemsPerPage: itemsPerPage,
// totalItems: dataVal.length,
totalItems: filteredData.length,
// activeColor: layoutColor, // your theme color
onPageChanged: (page) {
setState(() {
currentPage = page;
});
},
onItemsPerPageChanged: (items) {
setState(() {
itemsPerPage = items;
currentPage = 1;
});
},
),
),
], ],
),
),
); );
} }
// Widget _buildDataTable(BuildContext context) {
// if (filteredData.isEmpty) {
// return const SizedBox(
// height: 50,
// child: Center(child: Text('No available data')),
// );
// }
//
// final sortedData = [..._paginatedData];
// return ListView.builder(
// itemCount: ResponsiveLayout.isMobile(context)
// ? sortedData
// .length // only cards for mobile
// : sortedData.length + 1, // +1 for header in desktop
// itemBuilder: (context, index) {
// if (!ResponsiveLayout.isMobile(context) && index == 0) {
// return _buildHeader();
// }
//
// final startIndex = (currentPage - 1) * itemsPerPage;
// final item =
// sortedData[index - (ResponsiveLayout.isMobile(context) ? 0 : 1)];
// final sno = startIndex + index;
//
// return !ResponsiveLayout.isMobile(context)
// ? _buildDataRow(item, sno)
// : _buildDataCard(item, sno);
// },
// );
// }
Widget _buildDataTable(BuildContext context) { Widget _buildDataTable(BuildContext context) {
if (filteredData.isEmpty) { if (filteredData.isEmpty) {
return const SizedBox( return const SizedBox(
@ -524,24 +690,28 @@ class policylistState extends ConsumerState<policylist> {
} }
final sortedData = [..._paginatedData]; final sortedData = [..._paginatedData];
return ListView.builder(
itemCount: ResponsiveLayout.isMobile(context) if (ResponsiveLayout.isMobile(context)) {
? sortedData // Use Column instead of ListView
.length // only cards for mobile return Column(
: sortedData.length + 1, // +1 for header in desktop children: List.generate(sortedData.length, (index) {
itemBuilder: (context, index) { final startIndex = (currentPage - 1) * itemsPerPage;
if (!ResponsiveLayout.isMobile(context) && index == 0) { final item = sortedData[index];
return _buildHeader(); final sno = startIndex + index;
return _buildDataCard(item, sno);
}),
);
} }
// Desktop: keep ListView.builder
return ListView.builder(
itemCount: sortedData.length + 1,
itemBuilder: (context, index) {
if (index == 0) return _buildHeader();
final startIndex = (currentPage - 1) * itemsPerPage; final startIndex = (currentPage - 1) * itemsPerPage;
final item = final item = sortedData[index - 1];
sortedData[index - (ResponsiveLayout.isMobile(context) ? 0 : 1)];
final sno = startIndex + index; final sno = startIndex + index;
return _buildDataRow(item, sno);
return !ResponsiveLayout.isMobile(context)
? _buildDataRow(item, sno)
: _buildDataCard(item, sno);
}, },
); );
} }

View File

@ -1,44 +1,72 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:http/http.dart' as ref;
import 'package:shared_preferences/shared_preferences.dart';
import 'package:nhance_partner/presentation/providers/userRoleProvider.dart';
class TopBar extends StatelessWidget implements PreferredSizeWidget { import '../../core/routing/routes.dart';
import '../layouts/responsive_layout.dart';
import '../providers/userRoleProvider.dart';
class TopBar extends StatefulWidget implements PreferredSizeWidget {
final String title; final String title;
final bool isMobile; final bool isMobile;
final VoidCallback? onBack;
final VoidCallback? onMenuPressed;
final VoidCallback? onLogout; final VoidCallback? onLogout;
// final VoidCallback? onProfile;
final void Function(TapDownDetails details)? onProfile; final void Function(TapDownDetails details)? onProfile;
final VoidCallback? onMenuPressed;
final VoidCallback? onNotifications; final VoidCallback? onNotifications;
final int notificationCount;
const TopBar({ const TopBar({
super.key, super.key,
required this.title, required this.title,
this.isMobile = false, this.isMobile = false,
this.onBack,
this.onMenuPressed,
this.onLogout, this.onLogout,
this.onProfile, this.onProfile,
this.onNotifications, this.onNotifications,
this.notificationCount = 0, this.onMenuPressed,
}); });
@override
State<TopBar> createState() => _TopBarState();
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}
class _TopBarState extends State<TopBar> {
String? role;
@override
void initState() {
super.initState();
_loadUser();
}
Future<void> _loadUser() async {
final prefs = await SharedPreferences.getInstance();
setState(() {
role = prefs.getString('userRole') ?? "Guest";
});
print('Tpbn - $role');
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AppBar( return AppBar(
backgroundColor: const Color(0xFFD6F6F4), // light cyan backgroundColor: const Color(0xFFD6F6F4), // light cyan
elevation: 0, elevation: 0,
automaticallyImplyLeading: false, automaticallyImplyLeading: false,
titleSpacing: isMobile ? 0 : 30, titleSpacing: widget.isMobile ? 0 : 30,
title: Row( title: Row(
children: [ children: [
if (!isMobile) if (!widget.isMobile)
Image.asset( Image.asset(
"assets/login/nhance-partner-logo.png", "assets/login/nhance-partner-logo.png",
height: 60, height: 60,
width: 120, width: 120,
), ),
if (isMobile) ...[ if (widget.isMobile) ...[
Padding( Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Image.asset( child: Image.asset(
@ -75,6 +103,38 @@ class TopBar extends StatelessWidget implements PreferredSizeWidget {
// icon: const Icon(Icons.menu, color: Colors.black87), // icon: const Icon(Icons.menu, color: Colors.black87),
// onPressed: onMenuPressed, // onPressed: onMenuPressed,
// ), // ),
if (role == 'agent') ...[
GestureDetector(
onTap: () async {
final prefs = await SharedPreferences.getInstance();
await prefs.remove('enqAgentDataId');
context.go(AppRoutes.tabEnquiry);
// print('Export');
},
child: Container(
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Color(0xFF425B5B),
borderRadius: BorderRadius.circular(8.0),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Raise Enquiry',
style: GoogleFonts.inter(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 14,
),
),
],
),
),
),
],
SizedBox(width: 10),
Container( Container(
width: 40, width: 40,
height: 40, height: 40,
@ -84,10 +144,10 @@ class TopBar extends StatelessWidget implements PreferredSizeWidget {
), ),
child: IconButton( child: IconButton(
icon: const Icon(Icons.notifications_none, color: Colors.black87), icon: const Icon(Icons.notifications_none, color: Colors.black87),
onPressed: onNotifications, onPressed: widget.onNotifications,
), ),
), ),
if (!isMobile) ...[ if (!widget.isMobile) ...[
SizedBox(width: 10), SizedBox(width: 10),
Container( Container(
width: 40, width: 40,
@ -97,7 +157,7 @@ class TopBar extends StatelessWidget implements PreferredSizeWidget {
borderRadius: BorderRadius.circular(50.0), borderRadius: BorderRadius.circular(50.0),
), ),
child: GestureDetector( child: GestureDetector(
onTapDown: (details) => onProfile!(details), onTapDown: (details) => widget.onProfile!(details),
child: const Icon(Icons.person_outline, color: Colors.black87), child: const Icon(Icons.person_outline, color: Colors.black87),
), ),
), ),
@ -117,10 +177,9 @@ class TopBar extends StatelessWidget implements PreferredSizeWidget {
), ),
child: IconButton( child: IconButton(
icon: const Icon(Icons.logout, color: Colors.black87), icon: const Icon(Icons.logout, color: Colors.black87),
onPressed: onLogout, onPressed: widget.onLogout,
), ),
), ),
], ],
), ),
); );