如何从相册或相机获取圆形头像中的图片?

huangapple go评论75阅读模式
英文:

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?

enter image description here

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(),

huangapple
  • 本文由 发表于 2023年7月3日 18:06:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76603737.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定