firebase - 如何将 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");
});
}
解决方案
推荐阅读
- python - 索引/有序队列?
- microsoft-teams - 我可以为 Polly 或 Forms 等 MicrosoftTeams 创建上下文菜单条目吗
- gnuplot - 在gnuplot中添加百分比符号
- javascript - Javascript 进行事件调度的有效方法,
- c++ - C++ 代码来测试另一个 .cpp(如果可以编译它)
- r - as.Date 返回 NA
- google-sheets - 标记 Google 表格公式开头的字符是什么?
- bash - 从文件 A 中删除文件 B 的行
- unity3d - 在 2d unity 自上而下的游戏中发射激光
- r - 如何按日期将 R 文件拆分为 2