试试这个:
@override
Widget build(BuildContext context) {
int length = 20;
return Scaffold(
body: Center(
child: SizedBox(
height: 50,
child: Stack(
children: List.generate(length >= 4 ? 4 : length, (index) {
if (index >= 3) {
return Positioned(
left: index * 40,
child: ClipRRect(
borderRadius: BorderRadius.circular(50),
child: Container(
height: 50,
width: 50,
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.circular(50),
),
child: Center(
child: Text('+${length - 3}'),
),
),
),
);
}
return Positioned(
left: index * 40,
child: ClipRRect(
borderRadius: BorderRadius.circular(50),
child: SizedBox(
height: 50,
width: 50,
child: Image.asset(
'assets/test.png',
fit: BoxFit.cover,
),
),
),
);
})),
),
),
);
}