【发布时间】:2022-01-22 19:39:13
【问题描述】:
Flutter 中的设计。 关键是一行中的按钮数量取决于按钮的大小,因此 crossAxisCount 不固定。 如果没有足够的空间,我不知道如何在下一行放置一个按钮。
Container(
color: Colors.red,
width: appWidth * 0.8,
child: Row(
children: [
for (var i in provider.getFilterButtons)
Row(
children: [
SizedBox(
height: appHeight * 0.05,
child: OutlinedButton(
onPressed: () {},
child: Row(
children: [
Text(
'${i.name}: ${i.value}',
style: TextStyle(
fontSize: appHeight * 0.021),
),
IconButton(
padding: EdgeInsets.zero,
constraints:
const BoxConstraints(),
onPressed: () {},
iconSize: appHeight * 0.02,
icon: const Icon(
Icons.close,
color: Colors.black,
),
)
],
),
style: OutlinedButton.styleFrom(
onSurface: Colors.red,
side: const BorderSide(
color: AppColors.lightPurple,
),
),
),
),
SizedBox(width: appWidth * 0.02),
],
),
],
),
)
【问题讨论】:
-
您尝试过使用 Wrap 小部件吗? api.flutter.dev/flutter/widgets/Wrap-class.html
-
最好的方法是使用Wrap and Chip,Chip(label: Text("Chip"), deleteIcon: Icon(Icons.close), deleteIconColor: Colors.black54, onDeleted: () { print ("Delete"); }, deleteButtonTooltipMessage: "Tooltip", shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0), ), labelStyle: TextStyle(color: Colors.black54), backgroundColor: Colors.white, ),跨度>