一直在开发 Flutter 应用并根据一些 Firebase 数据动态构建一些容器。 我想知道是否有办法为容器(或任何不是按钮的小部件)获取 onTap 方法?
这是一个代码示例:
child: new Container(
//INSERT ONTAP OR ONPRESSED METHOD HERE
margin: const EdgeInsets.symmetric(vertical: 10.0),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Container(
margin: const EdgeInsets.only(right: 16.0),
child: new GoogleUserCircleAvatar(snapshot.value['images'][0]),
),
new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children : [
new Container(
padding: const EdgeInsets.only(bottom: 8.0),
child: new Text("${snapshot.value['name']}",
style: new TextStyle(
fontWeight: FontWeight.bold,
),
),
),
new Text("${snapshot.value['description']}",
style: new TextStyle(
color: Colors.grey[500],
),
),
]
)
],
),
最佳答案
您可以将您的 Container
包装在 InkWell
中或 GestureDetector
.不同之处在于 InkWell
是一个 Material 小部件,它显示接收到触摸的视觉指示,而 GestureDetector
是一个更通用的小部件,不显示任何视觉指示。
https://stackoverflow.com/questions/44317188/