flutter - 个人资料图片不会保持保存并正确适配
问题描述
我正在制作个人资料页面,但我不明白为什么我选择的图片没有保存并正确放置在现场。我使用此代码上传图片
Future _getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.gallery);
setState(() {
_image = File(pickedFile.path);
});
}
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;
setState(() {
print("Profile Picture uploaded");
Scaffold.of(context).showSnackBar(SnackBar(
content: Text('Profile Picture Uploaded'),
));
});
}
但我不知道我怎么能在这里调用函数来自动保存
child: Container(
height: 84,
width: 84,
//profilepic
child: GestureDetector(
onTap: _getImage,
child: CircleAvatar(
radius: 100,
child: ClipOval(
child: (_image != null)
? Image.file(
_image,
fit: BoxFit.fill,
)
: Image.network(
'https://icon-library.com/images/add-image-icon/add-image-icon-14.jpg',
fit: BoxFit.fill,
),
)),
),
),
解决方案
我重新阅读了你的问题,为了调用你的uploadPic()
函数,使onTap
函数像这样:
onTap: (){
uploadPic(context);
}
至于其余的代码,我需要知道 CircleAvatar 长什么样,_getImage 是什么。
推荐阅读
- ssl - 在 OpenJDK 11 中启用 SSL 证书吊销检查
- python - 如何为批量(JSON 对象数组)POST 请求中的每个实例返回错误消息?
- javascript - 如何在具有 20 多个网页的网站中为库维护相同的版本
- spring-cloud-dataflow - 在 PCF 中部署示例任务失败
- android - 如何在新的文本视图中更改小部件的文本?
- function - 所有 span 元素的功能 - 单击时更改颜色
- python - 使用 Python 处理包含矩阵的函数的牛顿方法
- xquery - 查询。如何查看当前的增量备份状态?
- python - grpc-Python max_workers 限制同时进程的数量
- c# - 反序列化对象