Handle tap in Flutter TableRow

Viewed 2993

I need to make the TableRow clickable and navigate to other screen but I cannot wrap TableRow with GestureDetector or Inkwell. How can I make the TableRow clickable. I have implemented as follows:

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,
                      ),
              ]),
3 Answers

I don't think you can do this,

You can use DataTable instead of Table widget, it will definitely meet your need.

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

Not for the whole row, but for the individual cells in a row you can use TableRowInkWell. TableRowInkWell goes inside a TableRow itself, wrapping a child. Here is the answer, with credit to 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')
      ]),
    ]),
  ],
)

It seems impossible to do this.

One thing you can try is adding inkwell to a table row of exactly the same size on top of the original table using a stack widget.

Related