'How to implement pagination in flutter?
I have data in column using List.generate which I want to paginate as in image attached. Could anyone guide me with this? Any help is appreciated. Thank You.
Column(
children: List.generate(
pList.newsList.length,
(index) => pList.newsList[index],
),
)
Solution 1:[1]
Also, Here I'm attaching a reference link for your better understanding
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Pagination View"),
),
body: Column(
children: <Widget>[
Container(
height: 50.0,
color: Colors.green,
child: Center(
child: Text(message),
),
),
Expanded(
child: ListView.builder(
itemCount: 30,
itemBuilder: (context, index) {
return ListTile(title: Text("Segment : $index"));
},
),
),
],
),
);
}
@override
void initState() {
//added the pagination function with listener
scrollcontroller.addListener(pagination);
super.initState();
}
//_subCategoryModel only use for check the length of product
void pagination() {
if ((scrollController.position.pixels ==
scrollController.position.maxScrollExtent) && (_subCategoryModel.products.length < total)) {
setState(() {
isLoading = true;
page += 1;
//add api for load the more data according to new page
});
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jijo Alexander |
