Flutter网络映像不适用于圆形头像 [英] Flutter Network Image does not fit in Circular Avatar

查看:139
本文介绍了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: Image.network("${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('https://via.placeholder.com/150'),
                backgroundColor: Colors.transparent,
              )

这篇关于Flutter网络映像不适用于圆形头像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆