import 'package:flutter/material.dart'; class PaginationControls extends StatelessWidget { final int currentPage; final int itemsPerPage; final int totalItems; final Function(int) onPageChanged; final Function(int) onItemsPerPageChanged; final Color? activeColor; const PaginationControls({ Key? key, required this.currentPage, required this.itemsPerPage, required this.totalItems, required this.onPageChanged, required this.onItemsPerPageChanged, this.activeColor = Colors.blue, // fallback if no color given }) : super(key: key); @override Widget build(BuildContext context) { int totalPages = (totalItems / itemsPerPage).ceil(); 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), DropdownButton( value: itemsPerPage, items: [10, 20, 50, 100] .map((value) => DropdownMenuItem( value: value, child: Text('$value', style: TextStyle( fontSize: 12, fontFamily: "Inter", )), )) .toList(), onChanged: (value) { if (value != null) { onItemsPerPageChanged(value); } }, style: TextStyle( fontSize: 12, color: Colors.black, fontFamily: "Inter", ), underline: SizedBox(), iconSize: 16, ), SizedBox(width: 16), IconButton( icon: Icon(Icons.arrow_back_ios_new, size: 10), onPressed: currentPage > 0 ? () => onPageChanged(currentPage - 1) : null, ), 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 } }, ), ), ), IconButton( icon: Icon(Icons.arrow_forward_ios, size: 10), onPressed: (currentPage + 1) * itemsPerPage < totalItems ? () => onPageChanged(currentPage + 1) : null, ), ], ); } }