import 'package:flutter/material.
dart';
class PaginationFooter extends StatefulWidget {
@override
_PaginationFooterState createState() => _PaginationFooterState();
}
class _PaginationFooterState extends State<PaginationFooter> {
int _itemsPerPage = 6;
int _totalItems = 30;
int _currentPage = 0;
List<int> _perPageOptions = [6, 10, 15, 20];
@override
Widget build(BuildContext context) {
int start = _currentPage * _itemsPerPage + 1;
int end = (_currentPage + 1) * _itemsPerPage;
if (end > _totalItems) end = _totalItems;
return Container(
color: Colors.black87,
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
'Items per page',
style: TextStyle(color: Colors.white),
),
SizedBox(width: 10),
Container(
padding: EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
),
child: DropdownButton<int>(
value: _itemsPerPage,
dropdownColor: Colors.black,
iconEnabledColor: Colors.white,
underline: SizedBox(),
style: TextStyle(color: Colors.white),
items: _perPageOptions.map((int value) {
return DropdownMenuItem<int>(
value: value,
child: Text(value.toString().padLeft(2, '0')),
);
}).toList(),
onChanged: (newValue) {
setState(() {
_itemsPerPage = newValue!;
_currentPage = 0;
});
},
),
),
SizedBox(width: 10),
Text(
'$start - ${end.toString().padLeft(2, '0')} of $_totalItems',
style: TextStyle(color: Colors.white),
),
SizedBox(width: 10),
IconButton(
icon: Icon(Icons.chevron_left, color: Colors.white),
onPressed: _currentPage > 0
? () {
setState(() {
_currentPage--;
});
}
: null,
),
IconButton(
icon: Icon(Icons.chevron_right, color: Colors.white),
onPressed: end < _totalItems
? () {
setState(() {
_currentPage++;
});
}
: null,
),
],
),
);
}
}