在Datatable上添加singlechildscroll视图



我有一个有4列的数据表,但当屏幕旋转时,目前只有3列显示,我可以看到所有4列,甚至无法滚动。

我试图在一个视图中看到4列,但我得到了这个错误:

lib/screens/home_screen.dart:79:29: Error: Cannot invoke a non-'const' constructor where a const expression is expected.
Try using a constructor or factory that is 'const'.
DataTable(
^^^^^^^^^
lib/screens/home_screen.dart:78:54: Error: Too many positional arguments: 0 allowed, but 1 found.
Try removing the extra positional arguments.
const SingleChildScrollView(
^
/C:/src/flutter/flutter/packages/flutter/lib/src/widgets/single_child_scroll_view.dart:140:9: Context: Found this candidate, but the arguments don't match.
const SingleChildScrollView({
^^^^^^^^^^^^^^^^^^^^^
Restarted application in 274ms.

这是表格的代码:

ExpansionTile(
title: const Text("Click Here to See table Name"),
children: [
const SingleChildScrollView(
DataTable(
columns: const <DataColumn>[
DataColumn(
label: Text(
'Sr.No',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
DataColumn(
label: Text(
'Website',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
DataColumn(
label: Text(
'Tutorial',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
DataColumn(
label: Text(
'Review',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
],
rows: const <DataRow>[
DataRow(
cells: <DataCell>[
DataCell(
Text('1'),
),
DataCell(
Text('https://flutter.dev/'),
),
DataCell(
Text('Flutter'),
),
DataCell(
Text('5*'),
),
],
),
DataRow(
cells: <DataCell>[
DataCell(
Text('2'),
),
DataCell(
Text('https://dart.dev/'),
),
DataCell(
Text('Dart'),
),
DataCell(
Text('5*'),
),
],
),
DataRow(
cells: <DataCell>[
DataCell(
Text('3'),
),
DataCell(
Text('https://pub.dev/'),
),
DataCell(
Text('Flutter Packages'),
),
DataCell(
Text('5*'),
),
],
),
],
),
),
],
),

我的问题是:如何在一个屏幕中查看表,以便将其包裹起来,或者将列缩小为在单个视图中查看?

您需要将DataTable传递给SingleChildScrollView's子级,您忘记添加child世界也需要传递scrollDirection

SingleChildScrollView(
scrollDirection: Axis.horizontal,// <---add this
child: DataTable(// <---add this
columns: <DataColumn>[
...
]
)
)

您必须将Datatable定义为子级,如果要定义多个,则需要删除列中的常量。

SingleChildScrollView(
child: DataTable( //Edited
columns: <DataColumn>[ //Edited
...
]
)
)

相关内容

  • 没有找到相关文章

最新更新