【发布时间】:2019-09-15 17:27:59
【问题描述】:
在下面的代码中,我检索了 Firebase 存储图像的下载链接,下载了带有链接的图像并保存到临时存储(缓存)。图像文件未按 Image 中的要求加载。网络小部件立即。当我重新启动应用程序时,它只会从缓存中获取文件。为什么应用需要重启才能更新缓存内容?为什么我不能立即访问缓存中的下载文件?
return FutureBuilder(
future: FirebaseStorage.instance
.ref()
.child(snapshot.data["sellerID"])
.child(snapshot.data["image"])
.getDownloadURL(),
builder: (context, snap) {
if (snap.hasData) {
writeToFile(snapshot.data);
return Image.network(snap.data);
}
return Image.file(
File(
"${MyApp.baseDirGlobal}/${snapshot.data["image"]}"),
fit: BoxFit.cover);
},
);
writeTofile 函数定义如下
void writeToFile(DocumentSnapshot snapshot) async {
final File file = File('${MyApp.baseDirGlobal}/${snapshot.data["image"]}');
if (await file.exists()) {
print("THE FILE EXISTS");
} else {
FirebaseStorage.instance
.ref()
.child(snapshot.data["sellerID"])
.child(snapshot.data["image"])
.writeToFile(file);
}
}
【问题讨论】:
标签: android firebase flutter firebase-storage