在 Flutter TableRow 中处理水龙头

Handle tap in 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插件,它一定能满足您的需求。

In DataRow there is a property named onSelectChanged, This is exactly what you want.

不是针对整行,而是针对一行中的单个单元格,您可以使用 TableRowInkWell。 TableRowInkWell 进入 TableRow 本身,包装 child。这是答案,归功于 SoloWofl93:How to use TableRowInkWell inside Table in flutter?

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')
      ]),
    ]),
  ],
)

这个好像做不到

您可以尝试的一件事是使用堆栈小部件将墨水瓶添加到原始 table 顶部完全相同大小的 table 行。