我想在我的 Flutter 应用程序中显示存储在 Firbase 存储中的图像,但我正在处理这个问题。我按照关于此 answer 的说明进行操作但是我的 ref()
总是这样:
我创建这个方法只是为了测试,当我尝试获取 DownloadURL 时,flutter 抛出了一个异常:
/flutter ( 4664): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════ I/flutter ( 4664): The following ArgumentError was thrown resolving an image codec: I/flutter ( 4664): Invalid argument(s): No host specified in URI file:///Instance%20of%20'Future'
void _locateFile() async{
final ref = FirebaseStorage.instance
.ref()
.child('avatars')
.child('simples')
.child('woman1.png');
var url = Uri.parse(await ref.getDownloadURL() as String);
print(url);
}
}
这是图片信息:
所以,如果有人能帮助我,我会很高兴:)
最佳答案
我想你想删除 as String
转换。现在您将它应用于 ref.getDownloadURL() 的结果.那当然是不正确的。您想要 await
它返回的 future ,而不是该对象的字符串版本。请注意,您尝试使用 Uri.parse()
解析的内容是“file:///Instance%20of%20'Future'”——看到“Instance of Future”这个词了吗?
您也可以暂时删除 Uri.parse()
并只专注于理解 getDownloadUrl() 返回的 future 值。一旦您理解了返回值,并且可以看到它包含您想要的内容,然后尝试用它做一些其他事情。
关于FirebaseStorage.instance.ref() 变为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53974295/