如何使用数据表在 flutter 中添加超过 5 列
How to add more than 5 columns in flutter using datatable
我在 flutter 中创建了一个数据表,问题是它只清楚地显示了 3 列,我无法向左或向右滚动以查看更多数据
这是我的代码的输出
这是我的数据表代码
Padding(padding: EdgeInsets.fromLTRB(5, 120, 0, 0),
child:DataTable(
columns: [
DataColumn(
label: Text(
'S.no',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)
)),
DataColumn(label: Text(
'Code',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)
)),
DataColumn(label: Text(
'Name',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)
)),
DataColumn(label: Text(
'Designation',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)
)),
],
rows: [
DataRow(cells: [
DataCell(Container(width:20,child:Text('1'))),
DataCell(Text('ENG-010')),
DataCell(Text('abc')),
DataCell(Text('Asst Software Engineer')),
]),
DataRow(cells: [
DataCell(Text('2')),
DataCell(Text('ENG-011')),
DataCell(Text('abc')),
DataCell(Text('MERN developer')),
]),
DataRow(cells: [
DataCell(Text('3')),
DataCell(Text('ENG-011')),
DataCell(Text('abc')),
DataCell(Text('Php developer')),
]),
],
),
)])
我在 DataRow 上使用了宽度但没有任何帮助。
https://youtu.be/ktTajqbhIcY?t=63
将您的 DataTable
包裹在 SingleChildScrollView
中以处理溢出。
您可能需要 2 个;一种用于垂直滚动,一种用于水平滚动。
SingleChildScrollView
scrollDirection: Axis.vertical
child: SingleChildScrollView
scrollDirection: Axis.horizontal
child: DataTable
我在 flutter 中创建了一个数据表,问题是它只清楚地显示了 3 列,我无法向左或向右滚动以查看更多数据
这是我的代码的输出
这是我的数据表代码
Padding(padding: EdgeInsets.fromLTRB(5, 120, 0, 0),
child:DataTable(
columns: [
DataColumn(
label: Text(
'S.no',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)
)),
DataColumn(label: Text(
'Code',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)
)),
DataColumn(label: Text(
'Name',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)
)),
DataColumn(label: Text(
'Designation',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)
)),
],
rows: [
DataRow(cells: [
DataCell(Container(width:20,child:Text('1'))),
DataCell(Text('ENG-010')),
DataCell(Text('abc')),
DataCell(Text('Asst Software Engineer')),
]),
DataRow(cells: [
DataCell(Text('2')),
DataCell(Text('ENG-011')),
DataCell(Text('abc')),
DataCell(Text('MERN developer')),
]),
DataRow(cells: [
DataCell(Text('3')),
DataCell(Text('ENG-011')),
DataCell(Text('abc')),
DataCell(Text('Php developer')),
]),
],
),
)])
我在 DataRow 上使用了宽度但没有任何帮助。
https://youtu.be/ktTajqbhIcY?t=63
将您的 DataTable
包裹在 SingleChildScrollView
中以处理溢出。
您可能需要 2 个;一种用于垂直滚动,一种用于水平滚动。
SingleChildScrollView
scrollDirection: Axis.vertical
child: SingleChildScrollView
scrollDirection: Axis.horizontal
child: DataTable