当我试图做UserCredential;await auth.currentUser!.updatePhotoURL(image);
时,这个错误发生了,我不知道如果我做错了什么,我无法弄清楚。所以如果你知道帮助。由于
late File? image;
从图库上传图片:
getFromGallery() async {
XFile? pickedFile = await ImagePicker().pickImage(
source: ImageSource.gallery,
maxWidth: 1800,
maxHeight: 1800,
);
if (pickedFile != null) {
setState(() {
image = File(pickedFile.path);
});
}
}
函数如下:
resetProfile(
File? image,
) async {
try {
UserCredential;
await auth.currentUser!.updatePhotoURL(image);
呼叫按钮:
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'),
),
这个错误似乎很明显:updatePhotoURL
期望你传递你想为用户设置的图像的URL,但是你试图传递一个File
给它。
如果你想使用本地的用户文件,你首先需要把它上传到某个地方,得到一个URL到那个地方,然后把那个URL传递给updatePhotoURL
。您可以通过Firebase将这些图像上传到Cloud Storage,如下所示:https://firebase.google.com/docs/storage/ios/upload-files
您直接在字符串中传递文件。获取图像的下载URL并将其传递到updatePhotoImage URL中。