Flutter中自动执行onTap事件解决

错误写法:

1
2
3
4
GestureDetector(
onTap: viewOrderList('all'),
child: ...
),

正确写法:

1
2
3
4
GestureDetector(
onTap: () => viewOrderList('all'),
child: ...
),

参考:https://stackoverflow.com/questions/50049683/flutter-gesturedetector-ontap-gets-triggered-automatically-how-to

1
2
3
4
5
6
7
8
There's a problem in your code at this line:

onTap: _changeCell(index),
Basically, instead of setting onTap to a method, you're calling the method directly and setting onTap to the result of that call (null). Each time the widget builds, it will call the function.

What you should be doing is this:

onTap: () => _changeCell(index)

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :