【发布时间】:2021-01-12 19:32:10
【问题描述】:
在我的应用程序中,我选择了带有图像选择器 dart 包 (pub.dev link) 的图像。然后我将此图像上传到云存储。我也可以从数据库中获取 url,但是如何将此 url 作为 photoUrl 添加到当前用户?如何更新 firebase 用户?
图像选择器代码:
getImage(BuildContext context) async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
if (image != null) {
cropImage(image);
_showDialog(context);
}
setState(() {
_image = image;
print("Image Path $_image");
});
}
上传代码:
uploadPic(BuildContext context) async {
String fileName = basename(_image.path);
StorageReference firebaseStorageRef =
FirebaseStorage.instance.ref().child("profilbilder/" + fileName);
StorageUploadTask uploadTask = firebaseStorageRef.putFile(_image);
StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
// Photo URL
var dowurl = await (await uploadTask.onComplete).ref.getDownloadURL();
String url = dowurl;
setState(() {
print("Profile Picture uploaded");
});
}
【问题讨论】:
-
这应该使用与上一个问题中用于更新用户显示名称相同的
updateProfile方法来完成。 stackoverflow.com/questions/63869474/…
标签: firebase flutter dart firebase-storage