本文介绍了Flutter网络映像不适用于圆形头像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从api检索一堆图像。我希望图像以圆形形式显示,因此我正在使用 CircleAvatar 小部件,但我一直在获取方形格式的图像。 这是图像的屏幕截图
I am trying to retrieve bunch of images from an api. I want the images to be displayed in Circular form so I am using CircleAvatar Widget, but I keep getting images in square format. Here is a screenshot of images
以下是我正在使用的代码
Here is the code I am using
ListTile(leading: CircleAvatar(child: Imagework("${snapshot.data.hitsList[index].previewUrl}",fit: BoxFit.scaleDown,)),),我尝试使用 BoxFit 的所有属性,例如 cover ,包含, fitWidth , fitHeight 等,但都不起作用。
I tryied using all the properties of BoxFit like cover, contain,fitWidth,fitHeight etc but none of them works.
推荐答案这将起作用:您需要使用 backgroundImage:属性以使其适合Circle。
This Will Work : You need to use backgroundImage:property in order to fit it in Circle.
CircleAvatar( radius: 30.0, backgroundImage: NetworkImage("${snapshot.data.hitsList[index].previewUrl}"), backgroundColor: Colors.transparent, )要与虚拟占位符一起检查:
To Check with Dummy Placeholder:
CircleAvatar( radius: 30.0, backgroundImage: NetworkImage('via.placeholder/150'), backgroundColor: Colors.transparent, )更多推荐
Flutter网络映像不适用于圆形头像
发布评论