[英]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.