我正在尝试在AppBar上显示Circle Avatar。
这是我的代码
AppBar(
...
actions: <Widget>[
CircleAvatar(
radius: 14,
backgroundImage: userProfilePictureValue != null
? NetworkImage(
userProfilePictureValue,
)
: Icon(Icons.add),
)
)
这是我尝试的第二种方法
AppBar(
...
actions: <Widget>[
Container(
width: 20,
height: 20,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color:Colors.blueGrey
),
child: StreamBuilder<String>(
stream: userProfilePicture,
builder: (context, snapshot) {
return ClipOval(
child: userProfilePictureValue != null
? CachedNetworkImage(
imageUrl:
"${userProfilePictureValue}",
fit: BoxFit.fill,
)
: Icon(
Icons.person,
size: 40,
color: Colors.white,
),
);
}),
)]
)
在第一种情况下,图像不显示为圆形,在第二种情况下,图像显示为蛋形而不是圆形。
答案 0 :(得分:2)
您可以将其包装在FlatButton之类的
中FlatButton(
child: CircleAvatar(
backgroundImage: AssetImage("your_image"),
),
)
答案 1 :(得分:0)
您的第一个选择是正确的方法。其不显示为圆形的原因是由于您定义的半径和所使用的图像大小。这是live的示例,根据图片具有正确的半径。
您的选择是
backgroundImage
,因为它期望ImageProvider
而不是Icon。因此,在这种情况下将失败。