【问题标题】:Why is there extra space at the end of my rows?为什么我的行尾有多余的空间?
【发布时间】: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


    【解决方案1】:

    不是 100% 确定,但请尝试将 mainAxisSize = MainAxisSize.min 添加到您的行中,如下所示:

    Widget w = Row(
      mainAxisSize = MainAxisSize.min,
      children: [
    

    【讨论】:

    • 谢谢!我只是自己想出了这个问题,并且正要自己回答这个问题!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    • 2016-09-25
    • 2012-04-09
    • 1970-01-01
    • 2020-02-07
    • 1970-01-01
    相关资源
    最近更新 更多