在Flutter TableRow中处理水龙头

时间:2020-08-04 12:49:52

标签: flutter flutter-table

我需要使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,
                      ),
              ]),

2 个答案:

答案 0 :(得分:2)

我认为您无法做到这一点,

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

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

答案 1 :(得分:1)

不是针对整行,而是针对一行中的单个单元格,您可以使用 TableRowInkWell。 TableRowInkWell 进入 TableRow 本身,包裹一个孩子。这是答案,归功于 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')
      ]),
    ]),
  ],
)