好的,我想要从LinearView中获取项目并获取它们的可见性,以便在隐藏的项目上释放内存。
这个可以实现吗? 你有其他的想法吗?
基本上,我想显示从URL动态下载的图像流,我希望它们在ListView中,这样人们就可以滚动查看它们,但如果我们只使用像这样的普通构建器加载ListView,
ListView lvb = new ListView.builder(
cacheExtent: 1.0,
itemBuilder: (BuildContext context, int index) {
return new ImageView(MyApp.imageLinks.values.elementAt(index));
},
);
如果一次下载所有项,设备会因为存储不足而无法运行。所以我想释放图片占用的内存,让用户可以加载更多的图片而无需担心内存问题。
此外,我希望每次只加载5张图片,1张显示在屏幕中间,2张在上方,2张在下方,以实现更快速、流畅的滚动效果。
我的问题:
- 有没有办法确定项目是否已经被绘制(在视图中)?
- 我可以限制我想要在LinearView中拥有的ImageView数量,但保持滚动能力吗?
编辑:如约提供ImageView类
class ImageView extends StatelessWidget {
String url;
ImageView([String url]) {
if (url != null) {
this.url = url;
}
print("New image");
}
@override
Widget build(BuildContext context) {
FractionallySizedBox fsb;
if (url != null) {
Image el = Image.network(
url,
scale: 0.1,
);
fsb = new FractionallySizedBox(
widthFactor: 1.0,
child: el,
);
print("New image created");
return fsb;
}
}
一旦ListView开始列出项目,就会在控制台中不断输出“New image created”。