问题描述
我正在尝试上传图片,并且相同的过程正在我的其他应用程序上运行,但是在这里出现了这些错误,请给我帮助吗?
i am trying to upload image, and the same process is working for my other app, but here it gives these errors, can you guy plz help?
Future getImage1() async {
// ignore: deprecated_member_use
var firstImage = await ImagePicker.pickImage(
source: ImageSource.gallery, imageQuality: 65);
setState(() {
_image1 = firstImage;
});
}
推荐答案
从版本firebase_storage 5.0.1开始:
您必须执行以下操作:
Starting from Version firebase_storage 5.0.1:
You have to do the following:
FirebaseStorage storage = FirebaseStorage.instance;
Reference ref = storage.ref().child("image1" + DateTime.now().toString());
UploadTask uploadTask = ref.putFile(_image1);
uploadTask.then((res) {
res.ref.getDownloadURL();
});
StorageReference
类已被删除,现在您必须使用 参考
. UploadTask
扩展了 Task
,它也实现了 Future< TaskSnapshot>
.因此,可以在类 UploadTask
上使用 Future
类中的所有方法.
StorageReference
class has been removed and now you have to use the class Reference
. UploadTask
extends Task
, which also implements Future<TaskSnapshot>
. Therefore all the methods that are in the class Future
can be used on the class UploadTask
.
因此,要获取图像的 url
,您需要使用 then()
方法,该方法注册一个在此将来完成时要调用的回调.
So to get the url
of the image, you need to use the then()
method which registers a callback to be called when this future completes.
这篇关于使用Firebase Storage时未定义的类StorageReference的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!