问题描述
我正在尝试上传图片,同样的过程也适用于我的其他应用程序,但是这里出现了这些错误,请问你们能帮忙吗?
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
.因此,Future
类中的所有方法都可以在 UploadTask
类上使用.
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()
方法,该方法注册一个回调,以便在此 future 完成时调用.
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 存储时未定义类 StorageReference的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!