[英]How to implement Lazy Loading
我有一个ListView
一次加载 10 个项目。 当我到达列表末尾时,我一次添加 10 个元素,因为我试图实现延迟加载 ListView,但我的问题是当我的列表中有 26 个元素时,它会加载前 20 个,但之后显示最后 6 个并显示剩余 4 个的范围错误。有人可以帮我解决这个问题吗? 这是我迄今为止的尝试-
NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification notification) {
if (notification is ScrollEndNotification) {
if (notification.metrics.extentBefore ==
notification.metrics.maxScrollExtent) {
if(listView.length%10 == listView.length%counter) {
counter+=10;
} else {
count.value = gameList.value.length%10;
//error comes when the total value of list is NOT a multiple of 10 (causes range error)
}
}
}
作为这段代码:
NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification notification) {
if (notification is ScrollEndNotification) {
if (notification.metrics.extentBefore ==
notification.metrics.maxScrollExtent) {
for(int i=0;i<NewItemList.length;i++)
setState(
{listView.add(NewItemList[i]);}); //here replace
//error comes when the total value of list is NOT a multiple of 10 (causes range error)
}
}
希望这会有所帮助。
onNotification: (ScrollNotification notification) {
if (notification is ScrollEndNotification) {
if (notification.metrics.extentBefore ==
notification.metrics.maxScrollExtent) {
if((listView.length - counter) >= 10 ) {
counter+=10;
} else {
counter += listView.length - counter;
}
}
}````
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.