一直在开发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是一个实质性的小部件,显示了已收到触摸的视觉指示,而GestureDetector另一个是通用的小部件,它未显示视觉指示。
Container
InkWell
GestureDetector