How do you center the label in a Flutter DataColumn widget?

Viewed 10749

I can center the DataCell in a DataRow but how do you do it for the DataColumn label?

I want the first DataColumn left justified and the rest centered. Wrapping the label in a Center widget does not take effect.

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 Answers

Found how:

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

You may want to wrap the contents of the Label in a Center widget. There's also an Align widget that uses alignment: Alignment.center and your Text as it's child.

This is how i resolved this issue :

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

I had the same problem and solved the issue by commenting the following code section in data_table.dart file.

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 ],
  );
}
Related