'DataTable's DataCell Background Color
I am trying to change the background color of a DataCell in DataTable. i.e
DataRow(cells: [
DataCell(Text(i[0].text)),
DataCell(Container(
child: Text(i[1].text),
color: customTheme.colors.bgColor,
)),
DataCell(Text(i[3].text)),
DataCell(FlutterLogo()),
]),
But the above code change a small portion of the DataCell (just the background color of
text) because the container has the size of the text.
How can I change the full DataCell background color?
Solution 1:[1]
Try below code hope its help to you. Refer flutter DataTable
DataTable(
headingRowColor: MaterialStateColor.resolveWith(
(states) => Colors.blue,
),//for heading row color
columns: <DataColumn>[
DataColumn(
label: Text(
'Name',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
DataColumn(
label: Text(
'Age',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
DataColumn(
label: Text(
'Role',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
],
rows: <DataRow>[
DataRow(
cells: <DataCell>[
DataCell(Text('Sarah')),
DataCell(Text('19')),
DataCell(Text('Student')),
],
),
DataRow(
color: MaterialStateProperty.all(Colors.red),//for data row color
cells: <DataCell>[
DataCell(Text('William')),
DataCell(Text('27')),
DataCell(Text('Associate Professor')),
],
),
],
),
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ravindra S. Patil |

