我正在尝试从 api 检索一堆图像。我希望图像以圆形形式显示,所以我使用 CircleAvatar
小部件,但我一直以方形格式获取图像。
这是图片的截图
这是我正在使用的代码
ListTile(leading: CircleAvatar(child: Image.network("${snapshot.data.hitsList[index].previewUrl}",fit: BoxFit.scaleDown,)),),
我尝试使用 BoxFit
的所有属性,例如 cover
、contain
、fitWidth
、fitHeight
等,但它们都不起作用。
最佳答案
这将起作用:您需要使用 backgroundImage:
property 以使其适合 Circle。
CircleAvatar(
radius: 30.0,
backgroundImage:
NetworkImage("${snapshot.data.hitsList[index].previewUrl}"),
backgroundColor: Colors.transparent,
)
使用虚拟占位符检查:
CircleAvatar(
radius: 30.0,
backgroundImage:
NetworkImage('https://via.placeholder.com/150'),
backgroundColor: Colors.transparent,
)
https://stackoverflow.com/questions/53513456/