为什么我的行末尾有额外的 space?
Why is there extra space at the end of my rows?
我创建了一个小部件来显示联赛 table,但在每一行的末尾都会得到一些额外的 space。
table 只是一个包含行小部件列表的列小部件。
每行包含一个 Container 列表,每个 Container 的宽度都是固定的。
看这张图:
'''
child: 中心(
child: ClipRRect(
borderRadius: BorderRadius.circular(10.0),
child:容器(
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()
])))));
'''
不是 100% 确定,但尝试将 mainAxisSize = MainAxisSize.min 添加到您的行中,就像这样:
Widget w = Row(
mainAxisSize = MainAxisSize.min,
children: [
我创建了一个小部件来显示联赛 table,但在每一行的末尾都会得到一些额外的 space。
table 只是一个包含行小部件列表的列小部件。
每行包含一个 Container 列表,每个 Container 的宽度都是固定的。
看这张图:
''' child: 中心( child: ClipRRect( borderRadius: BorderRadius.circular(10.0), child:容器(
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()
])))));
'''
不是 100% 确定,但尝试将 mainAxisSize = MainAxisSize.min 添加到您的行中,就像这样:
Widget w = Row(
mainAxisSize = MainAxisSize.min,
children: [