英文:
how to fetch an image from gallery or camera in circle avatar?
问题
我已经创建了一个页面,并添加了从相册和相机导入照片的功能。但是我遇到了一个问题,选择的照片不会出现在圆形头像中,而是出现在所有小部件的下方。有人能告诉我如何修复吗?
以下是调用函数:
File? image;
Future pickImage() async {
try {
final image = await ImagePicker().pickImage(source: ImageSource.gallery);
if (image == null) return;
final imageTemp = File(image.path);
setState(() => this.image = imageTemp);
} on PlatformException catch (e) {
print('Failed to pick image: $e');
}
}
Future pickImageC() async {
try {
final image = await ImagePicker().pickImage(source: ImageSource.camera);
if (image == null) return;
final imageTemp = File(image.path);
setState(() => this.image = imageTemp);
} on PlatformException catch (e) {
print('Failed to pick image: $e');
}
}
英文:
I have created a page and added a function to import photo from gallery and camera. but I have an issue with the photo selected appearing in the circle avatar. instead of image appearing in circle avatar it appear below all the widgets. can someone say how fix it?
below is the call function
File? image;
Future pickImage() async{
try{
final image = await ImagePicker().pickImage(source: ImageSource.gallery);
if(image == null) return;
final imageTemp = File(image.path);
setState(() => this.image = imageTemp);
} on PlatformException catch(e){
print('Failed to pick image: $e');
}
}
Future pickImageC() async{
try{
final image = await ImagePicker().pickImage(source: ImageSource.camera);
if(image == null) return;
final imageTemp = File(image.path);
setState(() => this.image = imageTemp);
} on PlatformException catch(e){
print('Failed to pick image: $e');
}
}
答案1
得分: 0
使用Image Provider来设置CircleAvatar中的图像。
image != null ? CircleAvatar(
radius: 50,
backgroundImage: FileImage(image!),
) : Container(),
英文:
Use Image Provide to set image in CircleAvatar.
image!=null?CircleAvatar(
radius: 50,
backgroundImage: FileImage(image!),
):Container(),
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论