CHANGE_PAGINATION
This commit is contained in:
parent
35229fa755
commit
8dea38b3a6
@ -292,7 +292,8 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
|||||||
|
|
||||||
Future<void> _showDetails(id) async {
|
Future<void> _showDetails(id) async {
|
||||||
_listDialogShown = true;
|
_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();
|
final String? token = await getToken();
|
||||||
String label = "";
|
String label = "";
|
||||||
List<Map<String, dynamic>> approverData = [];
|
List<Map<String, dynamic>> approverData = [];
|
||||||
@ -313,7 +314,9 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
|||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
label = data['data']['model_heading'] ?? "";
|
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 {
|
} else {
|
||||||
print('Failed to load');
|
print('Failed to load');
|
||||||
label = "Error - Failed to load data";
|
label = "Error - Failed to load data";
|
||||||
@ -326,7 +329,8 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
|||||||
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder:
|
||||||
|
(context) => AlertDialog(
|
||||||
title: Text(
|
title: Text(
|
||||||
label,
|
label,
|
||||||
style: GoogleFonts.poppins(
|
style: GoogleFonts.poppins(
|
||||||
@ -351,23 +355,47 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
|||||||
columns: [
|
columns: [
|
||||||
// DataColumn(label: Text('S.No', style: GoogleFonts.poppins(fontSize: 14, fontWeight: FontWeight.w600))),
|
// 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('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 index = entry.key + 1;
|
||||||
final item = entry.value;
|
final item = entry.value;
|
||||||
|
|
||||||
final approverIdKey = item.keys.firstWhere((k) => k.endsWith('_id'), orElse: () => '');
|
final approverIdKey = item.keys.firstWhere(
|
||||||
final statusKey = item.keys.firstWhere((k) => k.endsWith('_status'), orElse: () => '');
|
(k) => k.endsWith('_id'),
|
||||||
|
orElse: () => '',
|
||||||
|
);
|
||||||
|
final statusKey = item.keys.firstWhere(
|
||||||
|
(k) => k.endsWith('_status'),
|
||||||
|
orElse: () => '',
|
||||||
|
);
|
||||||
|
|
||||||
final approverId = item[approverIdKey]?.toString() ?? '-';
|
final approverId =
|
||||||
final statusText = item[statusKey]?.toString() ?? 'Unknown';
|
item[approverIdKey]?.toString() ?? '-';
|
||||||
|
final statusText =
|
||||||
|
item[statusKey]?.toString() ?? 'Unknown';
|
||||||
|
|
||||||
return DataRow(
|
return DataRow(
|
||||||
cells: [
|
cells: [
|
||||||
// DataCell(Text('$index')),
|
// DataCell(Text('$index')),
|
||||||
// DataCell(SizedBox(width: 120, child: Text(approverId, overflow: TextOverflow.ellipsis))),
|
// 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(),
|
}).toList(),
|
||||||
@ -376,7 +404,13 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
else
|
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),
|
onTap: () => _showDetails(plan.planId),
|
||||||
child:
|
child: Container(
|
||||||
Container(
|
|
||||||
width:
|
width:
|
||||||
double
|
double
|
||||||
.infinity, // Set your desired fixed size (equal width and height)
|
.infinity, // Set your desired fixed size (equal width and height)
|
||||||
@ -963,7 +997,8 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
|||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),),
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
DataCell(
|
DataCell(
|
||||||
Row(
|
Row(
|
||||||
@ -1156,10 +1191,11 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
|||||||
Column(
|
Column(
|
||||||
crossAxisAlignment:
|
crossAxisAlignment:
|
||||||
CrossAxisAlignment.start,
|
CrossAxisAlignment.start,
|
||||||
children: [GestureDetector(
|
children: [
|
||||||
onTap: () => _showDetails(plan.planId),
|
GestureDetector(
|
||||||
child:
|
onTap:
|
||||||
Container(
|
() => _showDetails(plan.planId),
|
||||||
|
child: Container(
|
||||||
padding: EdgeInsets.symmetric(
|
padding: EdgeInsets.symmetric(
|
||||||
horizontal: 8,
|
horizontal: 8,
|
||||||
vertical: 4,
|
vertical: 4,
|
||||||
@ -1168,9 +1204,8 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
|||||||
color: getStatusColor(
|
color: getStatusColor(
|
||||||
plan.statusValue,
|
plan.statusValue,
|
||||||
),
|
),
|
||||||
borderRadius: BorderRadius.circular(
|
borderRadius:
|
||||||
8,
|
BorderRadius.circular(8),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
plan.statusValue,
|
plan.statusValue,
|
||||||
@ -1182,7 +1217,8 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
|||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Column(
|
Column(
|
||||||
@ -1236,8 +1272,7 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
|||||||
ApiService.viewPlan(
|
ApiService.viewPlan(
|
||||||
context,
|
context,
|
||||||
plan.planId,
|
plan.planId,
|
||||||
isViewMode:
|
isViewMode: true,
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -1314,8 +1349,7 @@ class _ListAllPlansState extends State<ListAllPlans> {
|
|||||||
'Trip Comments',
|
'Trip Comments',
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
showDialog(
|
showDialog(
|
||||||
context:
|
context: context,
|
||||||
context,
|
|
||||||
builder:
|
builder:
|
||||||
(
|
(
|
||||||
context,
|
context,
|
||||||
|
|||||||
@ -425,7 +425,8 @@ class _ListPlansState extends State<ListPlans> {
|
|||||||
|
|
||||||
Future<void> _showDetails(id) async {
|
Future<void> _showDetails(id) async {
|
||||||
_listDialogShown = true;
|
_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();
|
final String? token = await getToken();
|
||||||
String label = "";
|
String label = "";
|
||||||
List<Map<String, dynamic>> approverData = [];
|
List<Map<String, dynamic>> approverData = [];
|
||||||
@ -446,7 +447,9 @@ class _ListPlansState extends State<ListPlans> {
|
|||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
label = data['data']['model_heading'] ?? "";
|
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 {
|
} else {
|
||||||
print('Failed to load');
|
print('Failed to load');
|
||||||
label = "Error - Failed to load data";
|
label = "Error - Failed to load data";
|
||||||
@ -459,7 +462,8 @@ class _ListPlansState extends State<ListPlans> {
|
|||||||
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder:
|
||||||
|
(context) => AlertDialog(
|
||||||
title: Text(
|
title: Text(
|
||||||
label,
|
label,
|
||||||
style: GoogleFonts.poppins(
|
style: GoogleFonts.poppins(
|
||||||
@ -484,23 +488,47 @@ class _ListPlansState extends State<ListPlans> {
|
|||||||
columns: [
|
columns: [
|
||||||
// DataColumn(label: Text('S.No', style: GoogleFonts.poppins(fontSize: 14, fontWeight: FontWeight.w600))),
|
// 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('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 index = entry.key + 1;
|
||||||
final item = entry.value;
|
final item = entry.value;
|
||||||
|
|
||||||
final approverIdKey = item.keys.firstWhere((k) => k.endsWith('_id'), orElse: () => '');
|
final approverIdKey = item.keys.firstWhere(
|
||||||
final statusKey = item.keys.firstWhere((k) => k.endsWith('_status'), orElse: () => '');
|
(k) => k.endsWith('_id'),
|
||||||
|
orElse: () => '',
|
||||||
|
);
|
||||||
|
final statusKey = item.keys.firstWhere(
|
||||||
|
(k) => k.endsWith('_status'),
|
||||||
|
orElse: () => '',
|
||||||
|
);
|
||||||
|
|
||||||
final approverId = item[approverIdKey]?.toString() ?? '-';
|
final approverId =
|
||||||
final statusText = item[statusKey]?.toString() ?? 'Unknown';
|
item[approverIdKey]?.toString() ?? '-';
|
||||||
|
final statusText =
|
||||||
|
item[statusKey]?.toString() ?? 'Unknown';
|
||||||
|
|
||||||
return DataRow(
|
return DataRow(
|
||||||
cells: [
|
cells: [
|
||||||
// DataCell(Text('$index')),
|
// DataCell(Text('$index')),
|
||||||
// DataCell(SizedBox(width: 120, child: Text(approverId, overflow: TextOverflow.ellipsis))),
|
// 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(),
|
}).toList(),
|
||||||
@ -509,7 +537,13 @@ class _ListPlansState extends State<ListPlans> {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
else
|
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(
|
DataCell(
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () => _showDetails(plan.planId),
|
onTap: () => _showDetails(plan.planId),
|
||||||
child:
|
child: Container(
|
||||||
Container(
|
|
||||||
width:
|
width:
|
||||||
double
|
double
|
||||||
.infinity, // Set your desired fixed size (equal width and height)
|
.infinity, // Set your desired fixed size (equal width and height)
|
||||||
@ -1119,7 +1152,8 @@ class _ListPlansState extends State<ListPlans> {
|
|||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),),
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
DataCell(
|
DataCell(
|
||||||
Row(
|
Row(
|
||||||
@ -1355,17 +1389,21 @@ class _ListPlansState extends State<ListPlans> {
|
|||||||
Row(
|
Row(
|
||||||
mainAxisAlignment:
|
mainAxisAlignment:
|
||||||
MainAxisAlignment.spaceBetween,
|
MainAxisAlignment.spaceBetween,
|
||||||
children: [GestureDetector(
|
children: [
|
||||||
|
GestureDetector(
|
||||||
onTap: () => _showDetails(plan.planId),
|
onTap: () => _showDetails(plan.planId),
|
||||||
child:
|
child: Container(
|
||||||
Container(
|
|
||||||
padding: EdgeInsets.symmetric(
|
padding: EdgeInsets.symmetric(
|
||||||
horizontal: 8,
|
horizontal: 8,
|
||||||
vertical: 4,
|
vertical: 4,
|
||||||
),
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: getStatusColor(plan.statusValue),
|
color: getStatusColor(
|
||||||
borderRadius: BorderRadius.circular(8),
|
plan.statusValue,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(
|
||||||
|
8,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
plan.statusValue,
|
plan.statusValue,
|
||||||
@ -1377,7 +1415,8 @@ class _ListPlansState extends State<ListPlans> {
|
|||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),),
|
),
|
||||||
|
),
|
||||||
// PlanPopupMenu(
|
// PlanPopupMenu(
|
||||||
// plan: plan,
|
// plan: plan,
|
||||||
// deletePlan: deletePlan,
|
// deletePlan: deletePlan,
|
||||||
@ -1663,6 +1702,7 @@ class _ListPlansState extends State<ListPlans> {
|
|||||||
// )
|
// )
|
||||||
// : buildMobileCardView(paginatedPlans),
|
// : buildMobileCardView(paginatedPlans),
|
||||||
),
|
),
|
||||||
|
|
||||||
PaginationControls(
|
PaginationControls(
|
||||||
currentPage: currentPage,
|
currentPage: currentPage,
|
||||||
itemsPerPage: itemsPerPage,
|
itemsPerPage: itemsPerPage,
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
|
||||||
class PaginationControls extends StatelessWidget {
|
class PaginationControls extends StatelessWidget {
|
||||||
final int currentPage;
|
final int currentPage;
|
||||||
@ -20,32 +21,98 @@ class PaginationControls extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
return Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
// Text(
|
||||||
'Items per page:',
|
// 'Items per page:',
|
||||||
style: TextStyle(
|
// style: TextStyle(
|
||||||
fontSize: 12,
|
// fontSize: 12,
|
||||||
fontWeight: FontWeight.w400,
|
// fontWeight: FontWeight.w400,
|
||||||
color: Colors.black87,
|
// color: Colors.black87,
|
||||||
fontFamily: "Inter",
|
// fontFamily: "Inter",
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
SizedBox(width: 8),
|
// SizedBox(width: 8),
|
||||||
DropdownButton<int>(
|
DropdownButton<int>(
|
||||||
value: itemsPerPage,
|
value: itemsPerPage,
|
||||||
items: [10, 20, 50, 100]
|
items:
|
||||||
.map((value) => DropdownMenuItem<int>(
|
[10, 20, 50, 100]
|
||||||
|
.map(
|
||||||
|
(value) => DropdownMenuItem<int>(
|
||||||
value: value,
|
value: value,
|
||||||
child: Text('$value',
|
child: Text(
|
||||||
style: TextStyle(
|
'$value',
|
||||||
fontSize: 12,
|
style: TextStyle(fontSize: 12, fontFamily: "Inter"),
|
||||||
fontFamily: "Inter",
|
),
|
||||||
)),
|
),
|
||||||
))
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
@ -66,51 +133,113 @@ class PaginationControls extends StatelessWidget {
|
|||||||
onPressed:
|
onPressed:
|
||||||
currentPage > 0 ? () => onPageChanged(currentPage - 1) : null,
|
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(
|
SingleChildScrollView(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
child: Row(
|
child: Row(children: _buildPageButtons()),
|
||||||
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
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.arrow_forward_ios, size: 10),
|
icon: Icon(Icons.arrow_forward_ios, size: 10),
|
||||||
onPressed: (currentPage + 1) * itemsPerPage < totalItems
|
onPressed:
|
||||||
|
(currentPage + 1) * itemsPerPage < totalItems
|
||||||
? () => onPageChanged(currentPage + 1)
|
? () => onPageChanged(currentPage + 1)
|
||||||
: null,
|
: 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)),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user