Merge with dashboard

This commit is contained in:
venba-Inspriron-3558 2025-07-17 12:02:35 +05:30
commit bc8968f9c5
3 changed files with 622 additions and 419 deletions

View File

@ -292,7 +292,8 @@ class _ListAllPlansState extends State<ListAllPlans> {
Future<void> _showDetails(id) async {
_listDialogShown = true;
final String apiUrldata = '$apiUrl/api/plans/get_plan_approval_status?plan_id=$id';
final String apiUrldata =
'$apiUrl/api/plans/get_plan_approval_status?plan_id=$id';
final String? token = await getToken();
String label = "";
List<Map<String, dynamic>> approverData = [];
@ -313,7 +314,9 @@ class _ListAllPlansState extends State<ListAllPlans> {
if (response.statusCode == 200) {
final data = json.decode(response.body);
label = data['data']['model_heading'] ?? "";
approverData = List<Map<String, dynamic>>.from(data['data']['approver_data'] ?? []);
approverData = List<Map<String, dynamic>>.from(
data['data']['approver_data'] ?? [],
);
} else {
print('Failed to load');
label = "Error - Failed to load data";
@ -326,7 +329,8 @@ class _ListAllPlansState extends State<ListAllPlans> {
showDialog(
context: context,
builder: (context) => AlertDialog(
builder:
(context) => AlertDialog(
title: Text(
label,
style: GoogleFonts.poppins(
@ -351,23 +355,47 @@ class _ListAllPlansState extends State<ListAllPlans> {
columns: [
// DataColumn(label: Text('S.No', style: GoogleFonts.poppins(fontSize: 14, fontWeight: FontWeight.w600))),
// DataColumn(label: Text('Approver ID', style: GoogleFonts.poppins(fontSize: 14, fontWeight: FontWeight.w600))),
DataColumn(label: Text('Status', style: GoogleFonts.poppins(fontSize: 14, fontWeight: FontWeight.w600))),
DataColumn(
label: Text(
'Status',
style: GoogleFonts.poppins(
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
),
],
rows: approverData.asMap().entries.map((entry) {
rows:
approverData.asMap().entries.map((entry) {
final index = entry.key + 1;
final item = entry.value;
final approverIdKey = item.keys.firstWhere((k) => k.endsWith('_id'), orElse: () => '');
final statusKey = item.keys.firstWhere((k) => k.endsWith('_status'), orElse: () => '');
final approverIdKey = item.keys.firstWhere(
(k) => k.endsWith('_id'),
orElse: () => '',
);
final statusKey = item.keys.firstWhere(
(k) => k.endsWith('_status'),
orElse: () => '',
);
final approverId = item[approverIdKey]?.toString() ?? '-';
final statusText = item[statusKey]?.toString() ?? 'Unknown';
final approverId =
item[approverIdKey]?.toString() ?? '-';
final statusText =
item[statusKey]?.toString() ?? 'Unknown';
return DataRow(
cells: [
// DataCell(Text('$index')),
// DataCell(SizedBox(width: 120, child: Text(approverId, overflow: TextOverflow.ellipsis))),
DataCell(SizedBox(child: Text(statusText, overflow: TextOverflow.ellipsis))),
DataCell(
SizedBox(
child: Text(
statusText,
overflow: TextOverflow.ellipsis,
),
),
),
],
);
}).toList(),
@ -376,7 +404,13 @@ class _ListAllPlansState extends State<ListAllPlans> {
),
)
else
Text("-- no data. --", style: GoogleFonts.poppins(fontSize: 14, fontWeight: FontWeight.w300)),
Text(
"-- no data. --",
style: GoogleFonts.poppins(
fontSize: 14,
fontWeight: FontWeight.w300,
),
),
],
),
),
@ -934,10 +968,10 @@ class _ListAllPlansState extends State<ListAllPlans> {
),
),
),
DataCell(GestureDetector(
DataCell(
GestureDetector(
onTap: () => _showDetails(plan.planId),
child:
Container(
child: Container(
width:
double
.infinity, // Set your desired fixed size (equal width and height)
@ -963,7 +997,8 @@ class _ListAllPlansState extends State<ListAllPlans> {
fontWeight: FontWeight.w400,
),
),
),),
),
),
),
DataCell(
Row(
@ -1156,10 +1191,11 @@ class _ListAllPlansState extends State<ListAllPlans> {
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [GestureDetector(
onTap: () => _showDetails(plan.planId),
child:
Container(
children: [
GestureDetector(
onTap:
() => _showDetails(plan.planId),
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
@ -1168,9 +1204,8 @@ class _ListAllPlansState extends State<ListAllPlans> {
color: getStatusColor(
plan.statusValue,
),
borderRadius: BorderRadius.circular(
8,
),
borderRadius:
BorderRadius.circular(8),
),
child: Text(
plan.statusValue,
@ -1182,7 +1217,8 @@ class _ListAllPlansState extends State<ListAllPlans> {
fontWeight: FontWeight.w600,
),
),
),),
),
),
],
),
Column(
@ -1236,8 +1272,7 @@ class _ListAllPlansState extends State<ListAllPlans> {
ApiService.viewPlan(
context,
plan.planId,
isViewMode:
true,
isViewMode: true,
);
},
),
@ -1314,8 +1349,7 @@ class _ListAllPlansState extends State<ListAllPlans> {
'Trip Comments',
onPressed: () {
showDialog(
context:
context,
context: context,
builder:
(
context,

View File

@ -425,7 +425,8 @@ class _ListPlansState extends State<ListPlans> {
Future<void> _showDetails(id) async {
_listDialogShown = true;
final String apiUrldata = '$apiUrl/api/plans/get_plan_approval_status?plan_id=$id';
final String apiUrldata =
'$apiUrl/api/plans/get_plan_approval_status?plan_id=$id';
final String? token = await getToken();
String label = "";
List<Map<String, dynamic>> approverData = [];
@ -446,7 +447,9 @@ class _ListPlansState extends State<ListPlans> {
if (response.statusCode == 200) {
final data = json.decode(response.body);
label = data['data']['model_heading'] ?? "";
approverData = List<Map<String, dynamic>>.from(data['data']['approver_data'] ?? []);
approverData = List<Map<String, dynamic>>.from(
data['data']['approver_data'] ?? [],
);
} else {
print('Failed to load');
label = "Error - Failed to load data";
@ -459,7 +462,8 @@ class _ListPlansState extends State<ListPlans> {
showDialog(
context: context,
builder: (context) => AlertDialog(
builder:
(context) => AlertDialog(
title: Text(
label,
style: GoogleFonts.poppins(
@ -484,23 +488,47 @@ class _ListPlansState extends State<ListPlans> {
columns: [
// DataColumn(label: Text('S.No', style: GoogleFonts.poppins(fontSize: 14, fontWeight: FontWeight.w600))),
// DataColumn(label: Text('Approver ID', style: GoogleFonts.poppins(fontSize: 14, fontWeight: FontWeight.w600))),
DataColumn(label: Text('Status', style: GoogleFonts.poppins(fontSize: 14, fontWeight: FontWeight.w600))),
DataColumn(
label: Text(
'Status',
style: GoogleFonts.poppins(
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
),
],
rows: approverData.asMap().entries.map((entry) {
rows:
approverData.asMap().entries.map((entry) {
final index = entry.key + 1;
final item = entry.value;
final approverIdKey = item.keys.firstWhere((k) => k.endsWith('_id'), orElse: () => '');
final statusKey = item.keys.firstWhere((k) => k.endsWith('_status'), orElse: () => '');
final approverIdKey = item.keys.firstWhere(
(k) => k.endsWith('_id'),
orElse: () => '',
);
final statusKey = item.keys.firstWhere(
(k) => k.endsWith('_status'),
orElse: () => '',
);
final approverId = item[approverIdKey]?.toString() ?? '-';
final statusText = item[statusKey]?.toString() ?? 'Unknown';
final approverId =
item[approverIdKey]?.toString() ?? '-';
final statusText =
item[statusKey]?.toString() ?? 'Unknown';
return DataRow(
cells: [
// DataCell(Text('$index')),
// DataCell(SizedBox(width: 120, child: Text(approverId, overflow: TextOverflow.ellipsis))),
DataCell(SizedBox(child: Text(statusText, overflow: TextOverflow.ellipsis))),
DataCell(
SizedBox(
child: Text(
statusText,
overflow: TextOverflow.ellipsis,
),
),
),
],
);
}).toList(),
@ -509,7 +537,13 @@ class _ListPlansState extends State<ListPlans> {
),
)
else
Text("-- no data. --", style: GoogleFonts.poppins(fontSize: 14, fontWeight: FontWeight.w300)),
Text(
"-- no data. --",
style: GoogleFonts.poppins(
fontSize: 14,
fontWeight: FontWeight.w300,
),
),
],
),
),
@ -1074,8 +1108,7 @@ class _ListPlansState extends State<ListPlans> {
DataCell(
GestureDetector(
onTap: () => _showDetails(plan.planId),
child:
Container(
child: Container(
width:
double
.infinity, // Set your desired fixed size (equal width and height)
@ -1119,7 +1152,8 @@ class _ListPlansState extends State<ListPlans> {
fontWeight: FontWeight.w400,
),
),
),),
),
),
),
DataCell(
Row(
@ -1355,17 +1389,21 @@ class _ListPlansState extends State<ListPlans> {
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [GestureDetector(
children: [
GestureDetector(
onTap: () => _showDetails(plan.planId),
child:
Container(
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
decoration: BoxDecoration(
color: getStatusColor(plan.statusValue),
borderRadius: BorderRadius.circular(8),
color: getStatusColor(
plan.statusValue,
),
borderRadius: BorderRadius.circular(
8,
),
),
child: Text(
plan.statusValue,
@ -1377,7 +1415,8 @@ class _ListPlansState extends State<ListPlans> {
fontWeight: FontWeight.w600,
),
),
),),
),
),
// PlanPopupMenu(
// plan: plan,
// deletePlan: deletePlan,
@ -1663,6 +1702,7 @@ class _ListPlansState extends State<ListPlans> {
// )
// : buildMobileCardView(paginatedPlans),
),
PaginationControls(
currentPage: currentPage,
itemsPerPage: itemsPerPage,

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class PaginationControls extends StatelessWidget {
final int currentPage;
@ -20,32 +21,98 @@ class PaginationControls extends StatelessWidget {
@override
Widget build(BuildContext context) {
int totalPages = (totalItems / itemsPerPage).ceil();
// int totalPages = (totalItems / itemsPerPage).ceil();
final int totalPages = (totalItems / itemsPerPage).ceil();
// return Row(
// mainAxisAlignment: MainAxisAlignment.end,
// children: [
// Padding(
// padding: const EdgeInsets.symmetric(vertical: 12),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.center,
// children: [
// DropdownButton<int>(
// value: itemsPerPage,
// items:
// [5, 10, 15, 20, 50].map((int value) {
// return DropdownMenuItem<int>(
// value: value,
// child: Text(
// ' $value ',
// style: GoogleFonts.poppins(fontSize: 15),
// ),
// );
// }).toList(),
// onChanged: (newValue) {
// if (newValue != null) {
// onItemsPerPageChanged(newValue);
// onPageChanged(1); // reset to first page
// }
// },
// ),
// IconButton(
// onPressed:
// currentPage > 1
// ? () => onPageChanged(currentPage - 1)
// : null,
// icon: Icon(Icons.chevron_left),
// ),
// for (int i = 1; i <= totalPages - 1; i++)
// Padding(
// padding: const EdgeInsets.symmetric(horizontal: 4),
// child: ElevatedButton(
// style: ElevatedButton.styleFrom(
// backgroundColor:
// currentPage == i - 1 ? activeColor : Colors.grey[300],
// foregroundColor:
// currentPage == i - 1 ? Colors.white : Colors.black,
// minimumSize: Size(36, 36),
// padding: EdgeInsets.zero,
// ),
// onPressed: () => onPageChanged(i - 1),
// child: Text(i.toString()),
// ),
// ),
// IconButton(
// onPressed:
// currentPage < totalPages - 1
// ? () => onPageChanged(currentPage + 1)
// : null,
// icon: Icon(Icons.chevron_right),
// ),
// ],
// ),
// ),
// ],
// );
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
'Items per page:',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w400,
color: Colors.black87,
fontFamily: "Inter",
),
),
SizedBox(width: 8),
// Text(
// 'Items per page:',
// style: TextStyle(
// fontSize: 12,
// fontWeight: FontWeight.w400,
// color: Colors.black87,
// fontFamily: "Inter",
// ),
// ),
// SizedBox(width: 8),
DropdownButton<int>(
value: itemsPerPage,
items: [10, 20, 50, 100]
.map((value) => DropdownMenuItem<int>(
items:
[10, 20, 50, 100]
.map(
(value) => DropdownMenuItem<int>(
value: value,
child: Text('$value',
style: TextStyle(
fontSize: 12,
fontFamily: "Inter",
)),
))
child: Text(
'$value',
style: TextStyle(fontSize: 12, fontFamily: "Inter"),
),
),
)
.toList(),
onChanged: (value) {
if (value != null) {
@ -66,51 +133,113 @@ class PaginationControls extends StatelessWidget {
onPressed:
currentPage > 0 ? () => onPageChanged(currentPage - 1) : null,
),
// SingleChildScrollView(
// scrollDirection: Axis.horizontal,
// child: Row(
// children: List.generate(totalPages, (index) {
// print("totalPagesList - $totalPages");
// // Only show 2 pages: currentPage and currentPage + 1
// if (index == currentPage || index == currentPage + 1) {
// return Padding(
// padding: const EdgeInsets.symmetric(horizontal: 4),
// child: ElevatedButton(
// onPressed: () => onPageChanged(index),
// style: ElevatedButton.styleFrom(
// backgroundColor:
// currentPage == index
// ? activeColor
// : Colors.grey[300]!,
// minimumSize: Size(30, 30),
// padding: EdgeInsets.zero,
// ),
// child: Text(
// '${index + 1}',
// style: TextStyle(
// fontSize: 12,
// fontFamily: "Inter",
// color:
// currentPage == index ? Colors.white : Colors.black,
// ),
// ),
// ),
// );
// } else {
// return SizedBox.shrink(); // Don't show other pages
// }
// }),
// ),
// ),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: List.generate(
totalPages,
(index) {
// Only show 2 pages: currentPage and currentPage+1
if (index == currentPage || index == currentPage + 1) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: ElevatedButton(
onPressed: () => onPageChanged(index),
style: ElevatedButton.styleFrom(
backgroundColor: currentPage == index
? activeColor
: Colors.grey[300]!,
minimumSize: Size(30, 30),
padding: EdgeInsets.zero,
),
child: Text(
'${index + 1}',
style: TextStyle(
fontSize: 12,
fontFamily: "Inter",
color: currentPage == index
? Colors.white
: Colors.black,
),
),
),
);
} else {
return SizedBox.shrink(); // Don't show other pages
}
},
),
),
child: Row(children: _buildPageButtons()),
),
IconButton(
icon: Icon(Icons.arrow_forward_ios, size: 10),
onPressed: (currentPage + 1) * itemsPerPage < totalItems
onPressed:
(currentPage + 1) * itemsPerPage < totalItems
? () => onPageChanged(currentPage + 1)
: null,
),
],
);
}
List<Widget> _buildPageButtons() {
final int totalPages = (totalItems / itemsPerPage).ceil();
List<Widget> buttons = [];
// Always show first page
buttons.add(_buildPageButton(0));
// Add left ellipsis if needed
if (currentPage > 2) {
buttons.add(_buildEllipsis());
}
// Add previous, current, next page if in range
for (int i = currentPage - 1; i <= currentPage + 1; i++) {
if (i > 0 && i < totalPages - 1) {
buttons.add(_buildPageButton(i));
}
}
// Add right ellipsis if needed
if (currentPage < totalPages - 3) {
buttons.add(_buildEllipsis());
}
// Always show last page
if (totalPages > 1) {
buttons.add(_buildPageButton(totalPages - 1));
}
return buttons;
}
Widget _buildPageButton(int pageIndex) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: ElevatedButton(
onPressed: () => onPageChanged(pageIndex),
style: ElevatedButton.styleFrom(
backgroundColor:
currentPage == pageIndex ? activeColor : Colors.grey[300],
foregroundColor:
currentPage == pageIndex ? Colors.white : Colors.black,
minimumSize: Size(36, 36),
padding: EdgeInsets.zero,
),
child: Text('${pageIndex + 1}'),
),
);
}
Widget _buildEllipsis() {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 6),
child: Text('...', style: TextStyle(fontSize: 16)),
);
}
}