如何在颤动中堆叠圆圈
How to stack circles in flutter
我想像图片中一样堆叠圆圈,我尝试使用 Stack 小部件来完成,但似乎不起作用。
它是否适合使用小部件?如果是,我该如何正确设置它,如果不是,我应该使用什么小部件?
感谢您的帮助。
您可以将 Stack Widget 与 CirlceAvatar 小部件一起使用 children,但在这种情况下,您还必须考虑是否有足够 space 来容纳所有项目和显示未见 children 的计数,我建议使用 overflow_view 包。它方便、维护良好且足够小,如果您不愿意添加额外的依赖项,您可以出售它。如果您决定使用它,它的自述文件中有简单的说明:
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,
);
},
)
正确:需要使用堆栈;我添加一个简单的例子:
Example
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,
),
),
)
],
),
);
我想像图片中一样堆叠圆圈,我尝试使用 Stack 小部件来完成,但似乎不起作用。
它是否适合使用小部件?如果是,我该如何正确设置它,如果不是,我应该使用什么小部件?
感谢您的帮助。
您可以将 Stack Widget 与 CirlceAvatar 小部件一起使用 children,但在这种情况下,您还必须考虑是否有足够 space 来容纳所有项目和显示未见 children 的计数,我建议使用 overflow_view 包。它方便、维护良好且足够小,如果您不愿意添加额外的依赖项,您可以出售它。如果您决定使用它,它的自述文件中有简单的说明:
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,
);
},
)
正确:需要使用堆栈;我添加一个简单的例子:
Example
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,
),
),
)
],
),
);