Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何实现延迟加载_Flutter_Dart - Fatal编程技术网

Flutter 如何实现延迟加载

Flutter 如何实现延迟加载,flutter,dart,Flutter,Dart,我有一个列表视图,一次加载10个项目。当我到达列表的末尾时,我一次添加10个元素,因为我试图实现延迟加载ListView,但我的问题是当我的列表中有26个元素时,它会加载前20个元素,但之后会显示最后6个元素,并显示剩余4个元素的范围错误。有人能帮我解决这个问题吗?这是我迄今为止的尝试- NotificationListener<ScrollNotification>( onNotification: (ScrollNotification notification) {

我有一个
列表视图
,一次加载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(
onNotification:(滚动通知){
如果(通知为ScrollEndNotification){
如果(notification.metrics.extentBefore==
notification.metrics.maxScrollExtent){
if(listView.length%10==listView.length%计数器){
计数器+=10;
}否则{
count.value=gameList.value.length%10;
//当列表的总值不是10的倍数时出错(导致范围错误)
}
}
}
  • 将“listView.length+=10;”替换为“listView.add(NewItemList[i]);”
按照本规范:

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)
      }
    }
NotificationListener(
onNotification:(滚动通知){
如果(通知为ScrollEndNotification){
如果(notification.metrics.extentBefore==
notification.metrics.maxScrollExtent){
对于(inti=0;我希望这会有所帮助

      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;
         }
          }
        }````

我特别想一次添加10个项目在将它们添加到列表之前选择新的10个项目的数量ListView是从模型列表ListView中列出的;然后设置状态();您能更新您的示例@Hossambo Bin Arefp吗请阅读我试图实现的目标