【发布时间】:2020-09-13 10:04:45
【问题描述】:
我创建了一个小部件来显示排名表,但在每行的末尾获得了一些额外的空间。
该表只是一个带有 Row 小部件列表的 Column 小部件。
每一行包含一个容器列表,每个容器都有固定的宽度。
看这张图:
''' 孩子:中心( 孩子:剪辑RRect( 边界半径:边界半径.圆形(10.0), 孩子:容器(
padding: EdgeInsets.all(10),
color: Colors.red,
child: Column(children: [
Row(
children: [
Container(child: Text('#', style: TextStyle(fontWeight: FontWeight.bold)), width: widths[0]),
Container(child: Text('Lag', style: TextStyle(fontWeight: FontWeight.bold)), width: widths[1]),
Container(child: Text('SP', style: TextStyle(fontWeight: FontWeight.bold)), width: widths[2]),
Container(child: Text('+', style: TextStyle(fontWeight: FontWeight.bold)), width: widths[3]),
Container(child: Text('=', style: TextStyle(fontWeight: FontWeight.bold)), width: widths[4]),
Container(child: Text('-', style: TextStyle(fontWeight: FontWeight.bold)), width: widths[5]),
Container(child: Text('PP', style: TextStyle(fontWeight: FontWeight.bold)), width: widths[6]),
Container(
child: Text(
'MP',
style: TextStyle(fontWeight: FontWeight.bold),
textAlign: TextAlign.right,
),
width: widths[7]),
],
),
...table.map((row) {
Widget w = Row(children: [
Container(child: Text('${row.pos}.'), width: widths[0], color: odd ? oddColor : evenColor),
Container(
child: Text(
row.name,
softWrap: false,
overflow: TextOverflow.fade,
),
width: widths[1],
color: odd ? oddColor : evenColor),
Container(child: Text('${row.sp}'), width: widths[2], color: odd ? oddColor : evenColor),
Container(child: Text('${row.wins}'), width: widths[3], color: odd ? oddColor : evenColor),
Container(child: Text('${row.draws}'), width: widths[4], color: odd ? oddColor : evenColor),
Container(child: Text('${row.losses}'), width: widths[5], color: odd ? oddColor : evenColor),
Container(child: Text('${row.pp}'), width: widths[6], color: odd ? oddColor : evenColor),
Container(
child: Text('${row.mp.toStringAsFixed(0)}', style: TextStyle(fontWeight: FontWeight.bold), textAlign: TextAlign.right),
width: widths[7],
color: odd ? oddColor : evenColor),
]);
odd = !odd;
return w;
}).toList()
])))));
'''
【问题讨论】:
标签: flutter layout row spacing