skip to Main Content

This error accur while I was trying to do UserCredential;await auth.currentUser!.updatePhotoURL(image); I don’t know If I done anything wrong I can’t figure it out . So if you know help. Thanks

late File? image;

Upload image from gallery:

getFromGallery() async {
    XFile? pickedFile = await ImagePicker().pickImage(
      source: ImageSource.gallery,
      maxWidth: 1800,
      maxHeight: 1800,
    );
    if (pickedFile != null) {
      setState(() {
        image = File(pickedFile.path);
      });
    }
  }

Here’s the function:

resetProfile(
    File? image,
    
  ) async {
    try {
      UserCredential;
      await auth.currentUser!.updatePhotoURL(image);

Button to called:

               ElevatedButton(
                      onPressed: () => resetProfile(image),
                      style: ElevatedButton.styleFrom(
                        primary: Colors.grey,
                        onPrimary: Colors.black,
                        elevation: 0.0,
                        shape: const RoundedRectangleBorder(
                          borderRadius: BorderRadius.zero,
                        ),
                      ),
                      child: const Text('Confirm'),
                    ),

2

Answers


  1. The error seems pretty clear: updatePhotoURL expects you to pass the URL of the image you want to set for the user, but you are trying to pass a File to it.

    If you want to use the local for file the user, you’ll first need to upload it somewhere, get a URL to that place, and then pass that URL to updatePhotoURL. One place you can upload such images would be into Cloud Storage through Firebase, as shown here: https://firebase.google.com/docs/storage/ios/upload-files

    Login or Signup to reply.
  2. You are directly passing the file inside a String. Get the download URL of an image and pass it inside the updatePhotoImage URL. This will work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search