Flutter TableRow中的手柄攻丝

mzillmmw  于 2023-08-07  发布在  Flutter
关注(0)|答案(3)|浏览(112)

我需要使TableRow可单击并导航到其他屏幕,但我不能用GestureDetector或Inkwell Package 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,
                      ),
              ]),

字符串

5fjcxozz

5fjcxozz1#

我觉得你做不到,
您可以使用DataTable来代替Tablewidget,它一定能满足您的需求。
DataRow中有一个名为onSelectChanged的属性,这正是您想要的。

mspsb9vt

mspsb9vt2#

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

字符串

o0lyfsai

o0lyfsai3#

这是不可能实现的,因为TableRow不是一个小部件,因此它不能被 Package 在其他小部件中,如InkWell
This answer是目前最好的选择。
您可以尝试的一个可能的解决方案是使用堆栈小部件在目标TableRow的顶部添加一个大小完全相同的InkWell。但这将是难以实施的,这不是一个干净的做法。
或者,您可以在表中需要处理抽头的每个单元格中保留InkWell,这将是多余的
在这个SO answer中有一个可能的解决方案。我还没试过呢。

相关问题