infinite_scroll_pagination
infinite_scroll_pagination copied to clipboard
Mulitple levels
I have a file with this structure: https://jsoneditoronline.org/#left=cloud.5c3ee044771a4f25ab22407409e0da1b (number of items in "listlevel1" may vary and reach up to 2000) How can I make sure that my list loads correctly as I go down? I have now done that it is loaded by 20 elements, but the whole list at once
`
class _State extends State<ShownSp> {
static const _pageSize = 20;
bool islast = false;
PagingController<int, Abit> _pagingController =
PagingController(firstPageKey: 0);
List<Abit> abs = List.empty();
@override
void initState() {
_pagingController.addPageRequestListener((pageKey) {
_fetchPage(pageKey);
});
super.initState();
}
void dispose() {
_pagingController.dispose();
super.dispose();
}
Future<void> _fetchPage(int pageKey) async {
try {
final List<Abit> newItems = List.empty(growable: true);
if (abs.length != 0) {
int min = 0;
if (_pageSize < abs.length - pageKey * _pageSize)
min = _pageSize;
else
min = abs.length - pageKey * _pageSize;
for (var i = 0; i < min; i++) {
newItems.add(abs[pageKey * _pageSize + i]);
}
islast = true;
}
final isLastPage = newItems.length < _pageSize;
if (isLastPage && islast) {
_pagingController.appendLastPage(newItems);
} else {
final nextPageKey = pageKey + 1;
_pagingController.appendPage(newItems, nextPageKey);
}
} catch (error) {
_pagingController.error = error;
print(error);
}
}
........
ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: mydata.dinlist.length,
itemBuilder: (BuildContext context, int index) {
abs = mydata.dinlist[index].abit;
islast = false;
_pagingController = PagingController(firstPageKey: 0);
_pagingController.addPageRequestListener((pageKey) {
_fetchPage(pageKey);
});
return Column(
children: [
Container(
color: Color.fromRGBO(216, 249, 170, 1),
child: ListTile(
title: Text(
mydata.dinlist[index].name + txtkolmest),
),
),
PagedListView<int, dynamic>(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
pagingController: _pagingController,
builderDelegate:
PagedChildBuilderDelegate<dynamic>(
itemBuilder: (BuildContext context1,
item, int index1) {
Abit a = item;
islast=true;
return (Text(a.fio))
}}}}
`