Flutter 手势检测器ontap不工作,但ONDUBLE tap工作。颤振
如果我使用ontap,则Gesturedetector不起作用,但如果我将其更改为双击,则会起作用Flutter 手势检测器ontap不工作,但ONDUBLE tap工作。颤振,flutter,dart,Flutter,Dart,如果我使用ontap,则Gesturedetector不起作用,但如果我将其更改为双击,则会起作用 Widget build(BuildContext context) { return Container( color: _color, child: GestureDetector( onTap: () { print('object');// does not work but if I change it to onDoubleTap it works.
Widget build(BuildContext context) {
return Container(
color: _color,
child: GestureDetector(
onTap: () {
print('object');// does not work but if I change it to onDoubleTap it works.
},
child: SizedBox(
child: ListTile(
leading: Icon(Icons.card_giftcard_outlined),
onLongPress: () {},
contentPadding:
EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0),
// tileColor: Colors.green,
title: Text(
msg,
style: TextStyle(fontSize: 19.0, fontWeight: FontWeight.normal),
),
horizontalTitleGap: 32.0,
),
),
),
),
);
}
}
这是颤振或飞镖中的错误,还是我遗漏了什么或做错了什么尝试放置容器而不是SizedBox,然后移除
onLongPress:(){},
并将其放入手势检测器中
GestureDetector(
onTap: () {
print('object');// does not work but if I change it to onDoubleTap it works.
},
onLongPress: () {
},
child: SizedBox(
child: ListTile(
leading: Icon(Icons.card_giftcard_outlined),
contentPadding:
EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0),
// tileColor: Colors.green,
title: Text(
msg,
style: TextStyle(fontSize: 19.0, fontWeight: FontWeight.normal),
),
horizontalTitleGap: 32.0,
),
),
),
),
您在
listile
中有onLongPress:
,这就是它不工作的原因。Chanage作为:
小部件构建(构建上下文){
返回容器(
颜色:_颜色,
儿童:手势检测器(
onTap:(){
印刷品(
“object”);//不起作用,但如果我将其更改为onDoubleTap,它就会起作用。
},
孩子:大小盒子(
孩子:ListTile(
前导:图标(图标、卡片、礼品卡),
内容填充:
边缘组。对称(水平:10.0,垂直:10.0),
//tileColor:Colors.green,
标题:正文(
味精,
样式:TextStyle(fontSize:19.0,fontWeight:fontWeight.normal),
),
水平标题AP:32.0,
),
),
),
);
}
如果您需要GestureDectector
的onTap
,您可以使用listile
的onTap
,如下所示:
小部件构建(构建上下文){
返回容器(
颜色:_颜色,
儿童:手势检测器(
孩子:大小盒子(
孩子:ListTile(
前导:图标(图标、卡片、礼品卡),
onLongPress:(){},
onTap:(){
打印(“你好”);
},
内容填充:
边缘组。对称(水平:10.0,垂直:10.0),
//tileColor:Colors.green,
标题:正文(
味精,
样式:TextStyle(fontSize:19.0,fontWeight:fontWeight.normal),
),
水平标题AP:32.0,
),
),
),
);
}
试着从ListTile中删除onLongPress:(){},
。天哪,我根本没注意到,谢谢你,它起作用了谢谢我忘了我没有注意到longpress。很高兴它帮了我,希望得到一个有标记的答案:)干杯:)谢谢我忘了我没有注意到longpress。