首页 > 解决方案 > 如何将 photoUrl 添加到当前用户?

问题描述

在我的应用程序中,我选择带有图像选择器 dart 包(pub.dev 链接)的图像。然后我将此图像上传到云存储。我也可以从数据库中获取 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");
    });
  }

标签: firebaseflutterdartfirebase-storage

解决方案


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

参考这里:管理用户

Firebase getUrl


推荐阅读