Jakob
Jakob

Reputation: 167

How can I add a photoUrl to the current user?

In my app I choose an image with the image picker dart package (pub.dev link). Then I upload this image to Cloud Storage. I also can get the url from the database, but how can I add this url to the current user as photoUrl? How can I update the firebase user?

image picker code:

  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");
    });
  }

upload code:

  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");
    });
  }

Upvotes: 0

Views: 1337

Answers (1)

s_o_m_m_y_e_e
s_o_m_m_y_e_e

Reputation: 406

You can use the FirebaseUser object to store a user's profile photo's url.

Refer here: Manage users.

And Firebase getUrl

Upvotes: 2

Related Questions