Flutter DataTable 中的排序图标未显示,我不确定这是否是一个错误,或者我的代码是否错误。
\n根据DataTable (Flutter Widget of the Week),我只需sortColumnIndex: 0在DataTable()
这是我正在使用的代码:
\nimport \'package:flutter/material.dart\';\n\nvoid main() {\n runApp(MyApp());\n}\n\nclass MyApp extends StatelessWidget {\n @override\n Widget build(BuildContext context) {\n return MaterialApp(\n title: \'Flutter DataTable\',\n home: DataScreen(),\n );\n }\n}\n\nclass DataScreen extends StatelessWidget {\n @override\n Widget build(BuildContext context) {\n return Scaffold(\n body: Center(\n child: DataTable(\n sortColumnIndex: 0,\n sortAscending: true,\n columns: [\n DataColumn(label: Text(\'Name\')),\n DataColumn(label: Text(\'Year\')),\n ],\n rows: [\n DataRow(cells: [\n DataCell(Text(\'Dash\')),\n DataCell(Text(\'2018\')),\n ]),\n DataRow(cells: [\n DataCell(Text(\'Gopher\')),\n DataCell(Text(\'2009\')),\n ]),\n ],\n ),\n ),\n );\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n我知道,在 DataTable #26845 上存在无法禁用问题排序的问题,并且有一个拉取请求[DataTable] 在不排序时隐藏箭头填充 #51667。但即使我更改为开发频道,排序箭头也没有显示。我也厌倦了Flutter.dev DataTable 类上的交互式代码示例
\n我测试过的版本:
\n所以我不确定我是否错过了什么,或者它是否是一个错误。
\n您必须设置功能:onSort
class DataScreen extends StatefulWidget {
@override
_DataScreenState createState() => _DataScreenState();
}
class _DataScreenState extends State<DataScreen> {
bool ascending = false;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: DataTable(
sortColumnIndex: 0,
sortAscending: ascending,
columns: [
DataColumn(
label: Text('Name'),
onSort: (columnIndex, ascending) {
setState(() {
this.ascending = ascending;
});
},
),
DataColumn(
label: Text('Year'),
),
],
rows: [
DataRow(cells: [
DataCell(
Text('Dash'),
),
DataCell(
Text('2018'),
),
]),
DataRow(cells: [
DataCell(
Text('Gopher'),
),
DataCell(
Text('2009'),
),
]),
],
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3171 次 |
| 最近记录: |