如何解决Flutter用Firebase保存Profilepicture
在我的应用程序中,我创建了一个网站,用户可以在该网站上从自己的画廊中选择其个人资料图片的图片。当用户选择图片时,URL或图片将存储在Firebase中。但是现在,例如当用户注销并返回到应用程序时,配置文件图片消失了。但是我现在想要var url = downUrl.toString();通过NetworkImage(url)放置在第二个脚本中; 但是当我这样做的时候,URL也没有红色下划线。有谁知道如何解决这个问题。请评论您的解决方案。
File _image;
Future getImage(BuildContext context) async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image = image;
print('Image Path $_image');
uploadPic(context);
});
}
Future uploadPic(BuildContext context) async {
String fileName = basename(_image.path);
StorageReference firebaseStorageRef = FirebaseStorage.instance.ref().child(
fileName);
StorageUploadTask uploadTask = firebaseStorageRef.putFile(_image);
StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
var downUrl = await (await uploadTask.onComplete).ref.getDownloadURL();
var url = downUrl.toString();
setState(() {
print('Profile Picture uploaded');
Scaffold.of(context).showSnackBar(
SnackBar(content: Text('Profile Picture Uploaded')));
});
}
Center(
child: Stack(
children: [
Container(
margin: EdgeInsets.fromLTRB(0,230,50),width: 100,height: 100,decoration: BoxDecoration(
border: Border.all(
width: 3,color: Theme.of(context).scaffoldBackgroundColor
),boxShadow: [BoxShadow(
spreadRadius: 2,blurRadius: 10,color: Colors.white.withOpacity(0.1),offset: Offset(0,10),),],shape: BoxShape.circle,image: DecorationImage(
fit: BoxFit.cover,image: (_image != null) ? FileImage(
_image)
: NetworkImage("https://www.senertec.de/wp-content/uploads/2020/04/blank-profile-picture-973460_1280.png"),)
),Positioned(
bottom: 50,right: 230,child: Container(
height: 30,width: 30,decoration: BoxDecoration(
shape: BoxShape.circle,color: Colors.white,child: IconButton(icon: Icon(Icons.edit),color: Colors.blue,iconSize: 15,onPressed: (){
getImage(context);
},)
],
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。