我有一个GestureDetector
在自定义无状态视图中。
什么时候onTap
触发后,我显示了一个显示一些信息的小吃店。
当用户快速多次单击时,它会永远显示小吃栏。
源代码 https://github.com/ammaratef45/zold-flutter-client/blob/f433b04fde3d0466dfdf1c76ed8197c1fdf8c108/zold_wallet/lib/information_view/information_view.dart#L29-L36
GestureDetector(
onTap: () {
Clipboard.setData(new ClipboardData(text: idText));
Scaffold.of(context).showSnackBar(SnackBar
(content: Text('ID copied')));
},
child: Icon(Icons.content_copy,),
}
我想禁用onTap
几秒钟后才能再次单击。
创建一个bool
标记并定义一个方法:
bool _enabled = true;
void _onTap () {
// Disable GestureDetector's 'onTap' property.
setState(() => _enabled = false);
// Enable it after 1s.
Timer(Duration(seconds: 1), () => setState(() => _enabled = true));
// Rest of your code...
}
Usage:
GestureDetector(
onTap: _enabled ? _onTap: null,
child: Icon(Icons.content_copy),
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)