[英]What is the best way to add multiple onTap events in listview flutter?
[英]How to add onTap() or onPressed() to ExpansionTileCard in flutter?
我在下面为 ListView.Builder 使用 ExpansionTileCard 小部件,我可以使用它生成列表,但是如果用户按下列表中的项目然后执行 FlutterToast 操作,我无法添加该功能,我试图使用 flutter package 找到解决方案,但尚未成功
请指导我如何做到这一点。
child: ExpansionTileCard(
leading: CircleAvatar(child: Image.network(widget.Picurl)),
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("text1"),
Text('text2'),
],
),
subtitle: Column(
children: <Widget>[
Row(
children: <Widget>[
Text("Text1"),
SizedBox(width: 5,),
Text("Text2")
],
),
],
),
children: <Widget>[
Divider(
thickness: 1.0,
height: 1.0,
),
Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
child: Text(
widget.postcontent,
style: Theme.of(context)
.textTheme
.body1
.copyWith(fontSize: 16),
),
),
),
ButtonBar(
alignment: MainAxisAlignment.spaceAround,
buttonHeight: 52.0,
buttonMinWidth: 90.0,
children: <Widget>[
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4.0)),
onPressed: () {
},
child: Column(
children: <Widget>[
Icon(Icons.star),
Padding(
padding: const EdgeInsets.symmetric(vertical: 2.0),
),
Text('Button1'),
],
),
),
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4.0)),
onPressed: () {
},
child: Column(
children: <Widget>[
Icon(Icons.open_in_browser),
Padding(
padding: const EdgeInsets.symmetric(vertical: 2.0),
),
Text('Button2'),
],
),
),
],
),
],
),
尝试使用 GestureDetector 进行包装。
只需将要注册轻击或按下手势的小部件放入GestureDetector
小部件和 select 所需手势事件的适当回调
GestureDetector(
onTap: () {
// your code here
},
child: ExpansionTileCard(
........
),
),
有关更多详细信息和手势选项: https://api.flutter.dev/flutter/widgets/GestureDetector-class.html
如果您想要在点击小部件时产生涟漪效果,您应该将小部件包装在InkWell
这是如何 -
InkWell(
onTap: () {
// your code here
},
child: ExpansionTileCard(
........
),
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.