从 Firebase 存储 Flutter 加载图像 [英] 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
类,如果使用,我如何首先获取存储在 Storage 中的图像的 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();
原创
<打击>
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 存储 Flutter 加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!