如何在Flutter DataColumn小部件中使标签居中?

时间:2019-06-16 00:13:38

标签: flutter dart flutter-layout

我可以将DataCell放在DataRow的中心,但是如何为DataColumn标签做呢?

我希望左边的第一个DataColumn对齐,其余的对齐。将标签包裹在“中心”小部件中不会生效。

new DataColumn(
            label: Center(
              child: Text(statName,textAlign: TextAlign.center,
                style: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold),),
            )
        );

Center Widget is not applied to Text child

4 个答案:

答案 0 :(得分:1)

这是我解决此问题的方式:

DataColumn(
            label: Center(
            widthFactor: 5.0, // You can set as per your requirement.
            child: Text(
            'View',
            style: style_16_bold_primary,
            ),
          ),
      ),

答案 1 :(得分:1)

找到了方法:

DataColumn(
    label: Expanded(
        child: Text(
  'Label',
  textAlign: TextAlign.center,
))),

答案 2 :(得分:0)

您可能希望将Label的内容包装在Center小部件中。还有一个Align小部件,它使用alignment: Alignment.center和您的Text作为其子级。

答案 3 :(得分:0)

我遇到了同样的问题,并通过注释了data_table.dart文件中的以下代码部分来解决了该问题。

if (onSort != null) {
  final Widget arrow = _SortArrow(
    visible: sorted,
    down: sorted ? ascending : null,
    duration: _sortArrowAnimationDuration,
  );
  const Widget arrowPadding = SizedBox(width: _sortArrowPadding);
  label = Row(
    textDirection: numeric ? TextDirection.rtl : null,
    children: <Widget>[ label, arrowPadding, arrow ],
  );
}
相关问题