firebase - 如何将图像从 Firebase 云存储加载到颤动
问题描述
我已将图像存储在 Firebase Cloud Storage 上,我想将它们放在图标上。我想要一个函数来传递图像的名称并为我获取该图像的 URL,但这种方法对我不起作用。
Future<String> downloadURLExample(product) async {
String downloadURL = await firebase_storage.FirebaseStorage.instance
.ref('product_images/fruits/$product.jfif')
.getDownloadURL();
return downloadURL;
}
String returnImg(String product){
downloadURLExample(product).then((value) => {
imgURL = value
});
return imgURL;
}
我这样称呼我的函数:
returnImg(apple)
解决方案
您应该使用await
异步功能:
await downloadURLExample(product);
这是完整的例子:
Future<String> downloadURLExample(product) async {
String downloadURL = await firebase_storage.FirebaseStorage.instance
.ref('product_images/fruits/$product.jfif')
.getDownloadURL();
return downloadURL;
}
String returnImg(String product) {
String imgURL = await downloadURLExample(product);
return imgURL;
}
您可以按如下方式调用该函数:
returnImg('apple');
您可以在此处async
阅读有关函数的更多信息。
推荐阅读
- rest - 也可以属于其他资源的资源的 REST API 设计最佳实践
- python - 我想使用 PRAW 为我的 reddit 帖子设置天赋,有人可以提出解决方案吗?
- php - PHP GET 参数
- ruby-on-rails - Rails 5:使用 gteq 进行选择的 select_tag 选项
- powerbi - 如何在 Power BI 桌面中创建切片器截至(最新)日期
- u-sql - 将参数传递给 U-SQL 分区函数
- c# - IdentityServer4 配置问题
- python - Seaborn color brewer 非交互式
- lotus-notes - 是否有任何关于 Lotus domino 应用程序开发的资源(PDF 或视频系列)
- ruby-on-rails - 几次 cmmits 后,我的 aws 密钥对在 github 上