简体   繁体   English

如何在 Flutter 中监听 DataTable 中的 DataRow 的点击

[英]How to listen for tap on DataRow inside DataTable in Flutter

I was able to setup a DataTable to display a bunch of data.我能够设置一个 DataTable 来显示一堆数据。 But want to navigate to another screen when a row is tapped.但是想要在点击一行时导航到另一个屏幕。

Unfortunately there is no onTap callback for DataRow.不幸的是,DataRow 没有 onTap 回调。

I ended up adding onTap for each DataCell which looks like a hacky solution.我最终为每个 DataCell 添加了 onTap,这看起来像是一个笨拙的解决方案。 Is there any other way to handle this?有没有其他方法可以处理这个问题?

You can wrap whole row with GestureDetector . 您可以使用GestureDetector包装整行。

GestureDetector(
  onTap: onTapFunction,
  child: Row(),
)

The onTap call in DataRow is the onSelectChanged function DataRow 中的 onTap 调用是 onSelectChanged 函数

DataRow(
    cells: [
       DataCell(Text("ID"))
      ,DataCell(Text("NAME"))
    ],
    onSelectChanged: (value) {
     // insert your navigation function here and use the selected value returned by the function
      Navigator.of(context).pop(value);
    }
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM