flutter DataTable遇到的坑
DataTable(// 表头颜色headingTextStyle: TextStyle(color: Colors.black,//fontSize: 14,// 表头字体粗细fontWeight: FontWeight.w900,),//horizontalMargin: 30.0,// 表头背景颜色
·
DataTable(
// 表头颜色
headingTextStyle: TextStyle(
color: Colors.black,
//fontSize: 14,
// 表头字体粗细
fontWeight: FontWeight.w900,
),
//horizontalMargin: 30.0,
// 表头背景颜色
//headingRowColor: MaterialStateProperty.all(Colors.blueGrey),
// 每列宽度设置
columnSpacing: 30.0,
//bAutoWidth: true,
sortColumnIndex: _sortColumnIndex, // 设置表格按哪一列排序
sortAscending: _sortAscending, // 设置表格是升序还是降序 false为升序
//onSelectAll: (bool value) {}, // 定制全选的动作
columns: [
// 数据表格的栏目
DataColumn(label: Text('年份')),
DataColumn(
label: Text('最低分'),
onSort: (int index, bool ascending) {
// 点击标题触发排序方法
setState(() {
_sortColumnIndex = index;
_sortAscending = ascending;
_items.sort((a, b) {
if (!ascending) {
final c = a;
a = b;
b = c;
}
return a.lowScore.compareTo(b.lowScore);
});
});
}),
DataColumn(label: Text('最低位次')),
DataColumn(label: Text('录取数')),
],
rows: _items.map((item) {
return DataRow(
cells: [
DataCell(Text(item.year)),
DataCell(Text('${item.lowScore}')),
DataCell(Text(item.lowNum)),
DataCell(Text('${item.personNum}')),
]);
}).toList(),
),
未设置排序与选项按钮
数据的定义方式
效果图
注意:headingRowColor: MaterialStateProperty.all(Colors.blueGrey),
flutter MaterialStateProperty颜色的设置方式,可真是坑苦了我
DataTable 列宽的设置方式:
columnSpacing: 30.0,
更多推荐
已为社区贡献11条内容
所有评论(0)