Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change background color of DataColumn in Flutter?

I have a DataTable widget for displaying some data in tabular format. I wasn't able to find any way to change the background color of the DataColumn, it defaults to white.

I tried wrapping the label inside a Container but that does not help since the container takes the dimensions of the child.

Is there any easier way to set the background color of `DataColum'?

Below is some code for reference -

DataTable(
  dataRowHeight: 70,
  headingRowHeight: 60,
  rows: List.generate(4, (index) {
    return DataRow(
      cells: <DataCell>[
        DataCell(
          Text("Number",),
        ),
        DataCell(
          Text(
          "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
          ),
        ),
      ]
    );
  }),
  columns: [
    DataColumn(
      label: Text("Name"),
    ),
    DataColumn(
      label: Text("Description"),
    ),
  ],
)
like image 846
thedarthcoder Avatar asked Nov 01 '19 07:11

thedarthcoder


People also ask

How do I change the background color of RaisedButton in Flutter?

What you can do is create a "color" property (not required to set any value for it) in Zone class. Then set the color property of RaisedButton to zone.


1 Answers

Now in flutter version 1.22, you can do it like this

DataTable(
    headingRowColor:
        MaterialStateColor.resolveWith((states) => Colors.blue),
    columns: [
       DataColumn(),
       DataColumn(),
                
    ],
           
    rows: [
      DataRow(
          cells: [
              DataCell(),
              DataCell(),
          ],
      ),
    ],
)
like image 175
Ali Akbar Afridi Avatar answered Nov 15 '22 10:11

Ali Akbar Afridi