从Firebase存储中加载图像 [英] Flutter Load Image from Firebase Storage
问题描述
我看到有很多示例,这些示例说明了如何使用Flutter将图像上传到Firebase存储,但实际上没有下载/读取/显示已上传的图像的任何示例。
I see there are a lot of examples on how to upload an image using flutter to firebase storage but nothing on actually downloading/reading/displaying one that's already been uploaded.
在Android中,我只是使用 Glide
来显示图像,如何在Flutter中显示图像?我是否使用 NetworkImage
类,如果是,如何首先获取存储在存储中的图像的URL?
In Android, I simply used Glide
to display the images, how do I do so in Flutter? Do I use the NetworkImage
class and if so, how do I first get the url of the image stored in Storage?
推荐答案
更新
在较新版本中使用
await ref.getDownloadURL();
请参见如何从Flutter中的UploadTaskSnapshot获取完整的下载网址?
原始
someMethod() async {
var data = await FirebaseStorage.instance.ref().child("foo$rand.txt").getData();
var text = new String.fromCharCodes(data);
print(data);
}
或
final uploadTask = imageStore.putFile(imageFile);
final url = (await uploadTask.future).downloadUrl;
在后一种情况下,您需要存储 downloadUrl
某个地方,然后使用 NetworkImage
或类似的东西进行渲染。
In the later case you'd need to store the downloadUrl
somewhere and then use NetworkImage
or similar to get it rendered.
这篇关于从Firebase存储中加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!