【发布时间】:2022-10-24 18:53:49
【问题描述】:
我正在尝试在ExpansionTile 中添加可折叠的表格,当单击文本时,表格会出现,但出现错误:
lib/screens/home_screen.dart:78:34: Error: Cannot invoke a non-'const' constructor where a const expression is expected.
Try using a constructor or factory that is 'const'.
child: DataTable(
^^^^^^^^^
lib/screens/home_screen.dart:77:25: Error: Method not found: 'widget'.
widget(
^^^^^^
lib/screens/home_screen.dart:75:42: Error: Too many positional arguments: 0 allowed, but 1 found.
Try removing the extra positional arguments.
const ExpansionTile(
^
/C:/src/flutter/flutter/packages/flutter/lib/src/material/expansion_tile.dart:51:9: Context: Found this candidate, but the arguments don't match.
const ExpansionTile({
^^^^^^^^^^^^^
Restarted application in 282ms.
这是有ExpansionTile的代码和需要添加的表格示例:
const ExpansionTile(
title: Text("Click Here to See table Name"),
widget(
child: 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*'),
),
],
),
],
),
),
),
这是所需结果的打印,如下所示:
我的问题:
由于我是新手,有很多关于如何添加表的答案,但我想了解为什么扩展表不接受表并显示此错误以及添加此表的最佳做法是什么
【问题讨论】:
-
错误说您输入了太多参数。扩展磁贴中的小部件有什么作用?
-
@Davis 它应该允许在单击文本时表格可折叠
-
如果它是外部小部件,请将代码添加到它。
标签: flutter dart flutter-layout