[英]How to stack circles in flutter
是正确的:你需要使用堆栈; 我添加一个简单的例子:
SizedBox(
width: 400,
height: 400,
child: Stack(
children: [
Positioned(
top: 0,
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: Image.network(
'https://images.unsplash.com/photo-1529665253569-6d01c0eaf7b6?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8cHJvZmlsZXxlbnwwfHwwfHw%3D&w=1000&q=80',
width: 100,
height: 100,
fit: BoxFit.cover,
),
),
),
Positioned(
left: 75,
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: Image.network(
'https://media.istockphoto.com/photos/side-view-of-one-young-woman-picture-id1134378235?k=20&m=1134378235&s=612x612&w=0&h=0yIqc847atslcQvC3sdYE6bRByfjNTfOkyJc5e34kgU=',
width: 100,
height: 100,
fit: BoxFit.cover,
),
),
),
Positioned(
left: 150,
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: Image.network(
'https://images.unsplash.com/photo-1529665253569-6d01c0eaf7b6?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8cHJvZmlsZXxlbnwwfHwwfHw%3D&w=1000&q=80',
width: 100,
height: 100,
fit: BoxFit.cover,
),
),
),
Positioned(
left: 225,
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: Image.network(
'https://media.istockphoto.com/photos/side-view-of-one-young-woman-picture-id1134378235?k=20&m=1134378235&s=612x612&w=0&h=0yIqc847atslcQvC3sdYE6bRByfjNTfOkyJc5e34kgU=',
width: 100,
height: 100,
fit: BoxFit.cover,
),
),
)
],
),
);
您可以使用带有 CirlceAvatar 小部件的 Stack 小部件作为定位的子部件,但在这种情况下,如果您还必须考虑是否有足够的空间来容纳所有项目并显示看不见的子部件的数量,我建议使用overflow_view package。它方便、维护良好且足够小,如果您不愿意添加额外的依赖项,您可以出售它。 如果您决定使用它,它的自述文件中有简单的说明:
OverflowView(
// Either layout the children horizontally (the default)
// or vertically.
direction: Axis.horizontal,
// The amount of space between children.
spacing: 4,
// The widgets to display until there is not enough space.
children: <Widget>[
for (int i = 0; i < _counter; i++)
AvatarWidget(
text: avatars[i].initials,
color: avatars[i].color,
)
],
// The overview indicator showed if there is not enough space for
// all chidren.
builder: (context, remaining) {
// You can return any widget here.
// You can either show a +n widget or a more complex widget
// which can show a thumbnail of not rendered widgets.
return AvatarWidget(
text: '+$remaining',
color: Colors.red,
);
},
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.