【发布时间】:2018-08-24 05:31:42
【问题描述】:
事实上,这在某种程度上是一个理论上的问题,因为我确实做到了这一点,但是由于加载了我手机中存在的所有图像而导致内存中断。以下是我将图像存储到列表中的方式。
final Directory extDir = await getExternalStorageDirectory();
extDir.list(recursive: true, followLinks: false)
.listen((FileSystemEntity entity) {
print(entity.path);
/* check for image and save */
if(entity.path.endsWith("jpg")
|| entity.path.endsWith("png")
|| entity.path.endsWith("gif")
) {
_PhoneImages.add(entity.path);
}...
所以,我拉出列表中的路径并在我的网格视图中显示如下..
new GridView.count(
shrinkWrap: true,
physics: new ClampingScrollPhysics(),
crossAxisCount: 2,
children: new List<Widget>.generate(_PhoneImages.length, (index) {
return new GridTile(
child: new GestureDetector(
child: new Stack(
children: [
new Card(
color: Colors.blue.shade200,
child: new Center(
child: new Image.file(
new File(_PhoneImages[index]),
),
),...
这确实显示了前几张图片,但会慢慢崩溃,并在“运行”控制台中显示以下内容
Lost connection to device
我必须重新开始。但当然,它在尝试加载时会做同样的事情。我在这里做错了什么?
【问题讨论】:
标签: gridview memory-leaks flutter