所以我有一个数据表,由于可用数据量的缘故,它可以水平和垂直滚动。我希望指定列名称的第一行在垂直向下滚动时始终可见,而最左侧的列在水平滚动时始终可见。
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text(appTitle),
),
body: DataTableWidget(),
);
class DataTableWidgetState extends State<DataTableWidget> {
@override
Widget build(BuildContext context) {
final width = 100 * cityColumns.length;
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: SizedBox(
width: width * 1.4,
child: ListView(
children: <Widget>[
buildDataTable(),
],
),
),
);
}
Widget buildDataTable() => DataTable(
sortAscending: ascending,
sortColumnIndex: 0,
columns: cityColumns
.map(
(String column) => DataColumn(
label: Text(column),
onSort: (int columnIndex, bool ascending) => onSortColumn(
columnIndex: columnIndex, ascending: ascending),
),
)
.toList(),
rows: cities
.map((City city) => DataRow(
selected: selectedCities.contains(city),
cells: [
DataCell(Text('${city.name}')),
DataCell(Text('${city.nation}')),
DataCell(Text('${city.name2}')),
DataCell(Text('${city.nation2}')),
DataCell(Text('${city.name3}')),
DataCell(Text('${city.nation3}')),
DataCell(Text('${city.population}')),
DataCell(Text('${city.nation}')),
],
))
.toList(),
);
}