Load more pagination in Listview flutter

 

Inside Listview use Load more for pagination

Add loadmore dependencies inside pubspec.yaml

loadmore: ^2.0.1

Now we need to manage page count use loadMoreCount here.

initialy loadMore is 0

int loadMoreCount = 0;

Now use LoadMore Widget inside your body.
body: LoadMore(
isFinish: loadMoreCount >= 5,
onLoadMore: _loadMore,
child: ListView(
children: <Widget>[
Container(
color: Colors.red,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(5)),
margin: const EdgeInsets.all(8.0),
padding: const EdgeInsets.only(left: 8.0),
child: TextField(
decoration: InputDecoration(
fillColor: Colors.red,
icon: Icon(
Icons.search,
color: Colors.black,
),
border: InputBorder.none,
hintText: 'Search Product and Category'),
),
),
),
],
),
),


inside loadmore function call your next API.
Future<bool> _loadMore() async {
print("onLoadMore");
await Future.delayed(Duration(seconds: 0, milliseconds: 100));
if (loadMore < subCategories.length) {
print(" loadmore $loadMoreCount");
_getProducts(subCategories[loadMoreCount]);
loadMoreCount++;
}
return true;
}

Comments

Popular posts from this blog

Flutter Bloc Pattern 8.0.0 Call API

Learn SQLite using flutter

Search by character in flutter