【发布时间】:2021-10-18 19:41:15
【问题描述】:
在我的颤振应用程序中,我将来自 Firebase 存储的 URL 存储在 Firestore 中。我预计会有空 URL,因为它取决于用户上传图像。在我的代码中,我正在检查空值,但由于某种原因,代码仍然尝试加载空值。如何正确防止颤振加载网络图像中的空值。我的加载代码如下:
Container(
width: 150,
height: 150,
child: ListView.builder(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.all(8),
itemCount: photoList.length,
itemBuilder: (BuildContext context, int index) {
print(photoList[index]);
return photoList[index] != null ? Image.network(photoList[index]) : Container(height:400,child: Text('No Images to Display'));
}
),
),
当没有图像时,上面的打印调试如下:
I/flutter (27038): url - null
当有图像时,就会有一个正确的 URL,并且图像加载没有任何问题。
所以不太清楚为什么 Flutter 仍在尝试加载 null,即使在 null 的情况下我想要一个文本框来代替
【问题讨论】:
标签: flutter google-cloud-firestore firebase-storage