我一直在查看 API 文档,但似乎无法设置标题行的背景颜色。有什么建议吗? https://api.flutter.dev/flutter/material/DataTable-class.html
我已经简单地做了这个,这对我有用
headingRowColor: MaterialStateColor.resolveWith(
(states) {
return HexColor('#222D65');
},
),
您可以使用
Stack
:
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: IntrinsicWidth(
child: Stack(
children: [
Container(
height: 100,
color: Colors.yellow,
),
DataTable(
headingRowHeight: 100,
dataRowHeight: 100,
columns: [
DataColumn(
label: Text("Col1"),
),
DataColumn(
label: Text("Col2"),
),
],
rows: List.generate(2, (index) {
return DataRow(cells: <DataCell>[
DataCell(
Text(
"row $index content1",
),
),
DataCell(
Text(
"row $index content2",
),
),
]);
}),
),
],
),
),
),
);
}
设置为容器高度的
100
是标题行的高度。 IntrinsicWidth
用于将 Stack
的宽度设置为其子级的宽度。
结果: