在Flutter中滚动时,PageView feed返回到第二索引

问题描述

因此,我正在使用Fluke的PageView进行Feed。我的供稿存储在Firestore中的文档中,并且显示图像URL。 Feed逻辑非常简单,它将首先加载2张图片,并以2的倍数继续加载。因此,我使用private void ShowCategoryView() { IsBrandView = false; } public void FilterbyBrand() { IsBrandView = true; BrandView.Filter = item => (item as Car).Category.Equals(_selectedCategory.Category,StringComparison.OrdinalIgnoreCase); OnPropertyChanged("BrandView"); } 进行滚动并通过Future获取我的图片网址并存储将它们放在PageView中,最初的2张图片可以正常工作,但问题出在后来。因此,要加载更多2张图像,我会检索它们并将它们附加到现有列表中。我已经检查了断点,它们可以正常工作,但是要刷新列表中新添加的图像URL,我必须调用List,我认为该错误存在。因此,错误基本上是,在2张初始图像之后,当我尝试滚动时,它会滚动并瞥见下一张图像,然后折叠并返回到setState()的第二个索引。

加载更多图片代码

PageView

更新:由于调用PageView.builder( ... if((index+1) % 2 == 0) { loadFeed(cIndex,dindex).then((value) { value.forEach((element) { imageList.add(element); }); setState(() {}); print("len: " + imageList.length.toString()); }); } ... ) Future<List> loadFeed(int cIndex,int dindex) async { int pastCIndex = await Feed().getCatIndex();//1 int newCIndex = cIndex + pastCIndex;//1+1 int pastdindex = await Feed().getDogIndex(); int newdindex = dindex + pastdindex; List<Map> newFeedList = new List(); newFeedList = await Feed().getFirestoreFeed(newCIndex,newdindex); // imageList.addAll(newFeedList); return newFeedList; } 函数,因此IT可能返回了上一个索引。因此,可以使用什么解决方案,因为我无法将itemBuilder函数转换为异步函数来检索更新的图像URL列表。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)