Dart 如何用flatter包装卡片中的行项目
我有一张包含一行项目(文本和复选框小部件)的卡片。问题是卡只能在每一行中填满有限的空间,但它不会进入下一行。我尝试使用wrap小部件,但没有效果。我一直在想: 正如你所看到的,这不是包装到下一个,而是试图把所有的东西都放在这一行。这是我的密码:Dart 如何用flatter包装卡片中的行项目,dart,flutter,row,word-wrap,Dart,Flutter,Row,Word Wrap,我有一张包含一行项目(文本和复选框小部件)的卡片。问题是卡只能在每一行中填满有限的空间,但它不会进入下一行。我尝试使用wrap小部件,但没有效果。我一直在想: 正如你所看到的,这不是包装到下一个,而是试图把所有的东西都放在这一行。这是我的密码: Widget _buildCategories() { return Card( margin: const EdgeInsets.only(top: 20.0), child: Padding( padding: cons
Widget _buildCategories() {
return Card(
margin: const EdgeInsets.only(top: 20.0),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text(
'Categories',
style: TextStyle(fontFamily: 'MonteSerrat', fontSize: 16.0),
),
Wrap(
children: <Widget>[
Row(
children: <Widget>[
_checkBox('Gaming'),
_checkBox('Sports'),
_checkBox('Casual'),
_checkBox('21 +'),
_checkBox('Adult'),
_checkBox('Food'),
_checkBox('Club'),
_checkBox('Activities'),
_checkBox('Shopping'),
],
)
],
)
],
),
));
}
Widget _checkBox(String category) {
return Expanded(
child: Column(
children: <Widget>[
Text(
'$category',
textAlign: TextAlign.center,
style: TextStyle(fontFamily: 'MonteSerrat'),
),
Checkbox(
value: false,
onChanged: (value) {
// We will update the value to the firebase data here
print('updated value to: $value');
},
)
],
));
}
Widget\u buildCategories(){
回程卡(
边距:仅限常量边集(顶部:20.0),
孩子:填充(
填充:常数边集全部(20.0),
子:列(
儿童:[
正文(
“类别”,
样式:TextStyle(fontFamily:“蒙特塞拉特”,fontSize:16.0),
),
包裹(
儿童:[
划船(
儿童:[
_复选框(“游戏”),
_复选框(“运动”),
_复选框(‘休闲’),
_复选框('21+'),
_复选框(“成人”),
_复选框(“食品”),
_复选框(“俱乐部”),
_复选框(“活动”),
_复选框(“购物”),
],
)
],
)
],
),
));
}
小部件_复选框(字符串类别){
扩大回报(
子:列(
儿童:[
正文(
“$category”,
textAlign:textAlign.center,
样式:TextStyle(fontFamily:“蒙特塞拉特”),
),
复选框(
值:false,
一旦更改:(值){
//我们将在此处更新firebase数据的值
打印(“将值更新为:$value”);
},
)
],
));
}
我通过以下更改修复了您的代码:
- 已删除
内的小部件行
包装
- 已删除扩展的
小部件
- 将属性
添加到maxLines
小部件中Text
Widget _buildCategories() { return Card( margin: const EdgeInsets.only(top: 20.0), child: Padding( padding: const EdgeInsets.all(20.0), child: Column( children: <Widget>[ Text( 'Categories', style: TextStyle(fontFamily: 'MonteSerrat', fontSize: 16.0), ), Wrap( children: <Widget>[ _checkBox('Gaming'), _checkBox('Sports'), _checkBox('Casual'), _checkBox('21 +'), _checkBox('Adult'), _checkBox('Food'), _checkBox('Club'), _checkBox('Activities'), _checkBox('Shopping') ], ) ], ), )); } Widget _checkBox(String category) { return Column( children: <Widget>[ Text( '$category', maxLines: 1, textAlign: TextAlign.center, style: TextStyle(fontFamily: 'MonteSerrat'), ), Checkbox( value: false, onChanged: (value) { // We will update the value to the firebase data here print('updated value to: $value'); }, ) ], ); } }
更多信息请点击此处:因此
小部件是关键。谢谢你的信息。包装
Wrap( runSpacing: 5.0, spacing: 5.0,