如何将photoUrl添加到当前用户?

时间:2020-09-26 18:59:48

标签: firebase flutter dart firebase-storage

在我的应用中,我选择了带有图像选择器飞镖包(pub.dev link)的图像。然后,我将此图像上传到Cloud Storage。我也可以从数据库中获取该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");
    });
  }

1 个答案:

答案 0 :(得分:1)

您可以使用FirebaseUser对象存储用户的个人资料照片的网址。

在这里参考:Manage users

还有Firebase getUrl