我有一个DataTable
小部件,用于以表格格式显示一些数据。我找不到任何方法来更改DataColumn
的背景颜色,它默认为白色。
我尝试将label
包装在Container
内,但这无济于事,因为容器采用了孩子的尺寸。
有没有更简单的方法来设置'DataColum'的背景色?
下面是一些可供参考的代码-
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"),
),
],
)
[Container
与BoxDecoration
->Column
/ Row
-> DataTable
] >>
您也可以使用BoxDecoration
的gradient
属性。
child: Container(
width: MediaQuery.of(context).size.width - 40.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
color: Color(0xff5a348b),
gradient: LinearGradient(
colors: [Color(0xffebac38), Color(0xffde4d2a)],
begin: Alignment.centerRight,
end: Alignment(-1.0, -2.0)), //Gradient
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
children: <Widget>[
DataTable(
columns: <DataColumn>[
DataColumn(
label: Text(
'Storage',
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
),
),
),
DataColumn(
label: Text(
'1TB',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 16.0,
),
),
),
],
rows: <DataRow>[
DataRow(cells: <DataCell>[
DataCell(
Text(
'Smart synchronization',
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
),
),
),
DataCell(
Icon(
Icons.add,
color: Colors.white54,
),
),
]),
DataRow(cells: <DataCell>[
DataCell(
Text(
'Full text search',
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
),
),
),
DataCell(
Icon(
Icons.edit,
color: Colors.white54,
),
),
]),
],
),
],
),
),
],
),
),