Flutter DataTableのヘッダーの背景色を設定するサンプル
環境
Windows11 pro 64bit
Flutter 3.3.7
構文
headingRowColor: MaterialStateProperty.resolveWith((states) {
return /*ヘッダーの背景色*/;
}),
headingRowColor: MaterialStateProperty.resolveWith((states) {
return /*ヘッダーの背景色*/;
}),
headingRowColor: MaterialStateProperty.resolveWith((states) { return /*ヘッダーの背景色*/; }),
DataTableのヘッダーの背景色を設定するには、引数「headingRowColor」を使います。
引数「headingRowColor」に「MaterialStateProperty.resolveWith」を指定します。
使用例
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: DataTable(
headingRowColor: MaterialStateProperty.resolveWith((states) {
return Colors.green;
}),
columns: [
DataColumn(
label: Text('xxx'),
),
xxx
],
rows: _list
.map(
(e) => DataRow(
cells: [
DataCell(
Text('${e['xxx']}'),
),
xxx
],
),
)
.toList(),
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: DataTable(
headingRowColor: MaterialStateProperty.resolveWith((states) {
return Colors.green;
}),
columns: [
DataColumn(
label: Text('xxx'),
),
xxx
],
rows: _list
.map(
(e) => DataRow(
cells: [
DataCell(
Text('${e['xxx']}'),
),
xxx
],
),
)
.toList(),
),
),
);
}
@override Widget build(BuildContext context) { return Scaffold( body: Center( child: DataTable( headingRowColor: MaterialStateProperty.resolveWith((states) { return Colors.green; }), columns: [ DataColumn( label: Text('xxx'), ), xxx ], rows: _list .map( (e) => DataRow( cells: [ DataCell( Text('${e['xxx']}'), ), xxx ], ), ) .toList(), ), ), ); }