Flutter TableRow中的手柄敲击



我需要使TableRow可点击并导航到其他屏幕,但我无法用GestureDetector或Inkwell包装TableRow。如何使TableRow可单击。我已经实现如下:

for (int i = 0; i < menuList.length; i++)
TableRow(children: [
SizedBox(
width: 5,
),
Text((i + 1).toString()),
Text(menuList[i].name),
Text(menuList[i].price.toString()),
Text(menuList[i].maxQty.toString()),
menuList[i].status == 0
? Text(
menuList[i].foodStatus,
style: TextStyle(color: Colors.red),
)
: YourListViewItem(
id: menuList[i].id,
index: menuList[i].status,
),
]),

我认为你做不到,

您可以使用DataTable而不是Table小部件,它肯定会满足您的需求。

DataRow中有一个名为onSelectChanged的属性,这是正是你想要的。

不是针对整行,而是针对一行中的单个单元格,您可以使用TableRowInkWell。TableRowInkWell进入TableRow本身,包裹一个子对象。以下是答案,归功于SoloWofl93:如何在flutter中使用TableRowInkWell?

Table(
border: TableBorder.all(),
children: [
TableRow(children: [

// HERE IT IS...
TableRowInkWell(
onTap: (){},
child: Column(children: [
Icon(
Icons.account_box,
size: iconSize,
),
Text('My Account'),
]),
),

Column(children: [
Icon(
Icons.settings,
size: iconSize,
),
Text('Settings')
]),
]),
],
)

这是不可能实现的,因为TableRow不是一个小部件,因此它不能封装在InkWell等其他小部件中。

这个答案是你目前的最佳选择。

您可以尝试的一种可能的解决方案是使用堆栈小部件在目标TableRow的顶部添加一个大小完全相同的InkWell。但这将很难实施,而且这不是一种干净的方式

或者,您可以在表中需要处理抽头的每个单元格中保留一个InkWell,这将是冗余的

这个SO答案中有一个可能的解决方案。不过我还没试过。

最新更新