1 Star 0 Fork 0

PurpleAxis/dev_demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
single_touch_helper.dart 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
淡心紫愿 提交于 2023-08-30 23:50 . feat: 添加代码片段
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
class _SingleTouchRecognizer extends OneSequenceGestureRecognizer {
int _p = 0;
@override
void addAllowedPointer(PointerDownEvent event) {
//first register the current pointer so that related events will be handled by this recognizer
startTrackingPointer(event.pointer);
//ignore event if another event is already in progress
if (_p == 0) {
resolve(GestureDisposition.rejected);
_p = event.pointer;
} else {
resolve(GestureDisposition.accepted);
}
}
@override
// TODO: implement debugDescription
String get debugDescription => throw UnimplementedError();
@override
void didStopTrackingLastPointer(int pointer) {
// TODO: implement didStopTrackingLastPointer
}
@override
void handleEvent(PointerEvent event) {
if (!event.down && event.pointer == _p) {
_p = 0;
}
}
}
class SingleTouchRecognizerWidget extends StatelessWidget {
final Widget child;
SingleTouchRecognizerWidget({this.child});
@override
Widget build(BuildContext context) {
return RawGestureDetector(
gestures: <Type, GestureRecognizerFactory>{
_SingleTouchRecognizer: GestureRecognizerFactoryWithHandlers<_SingleTouchRecognizer>(
() => _SingleTouchRecognizer(),
(_SingleTouchRecognizer instance) {},
),
},
child: child,
);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/purpleaxis/dev_demo.git
git@gitee.com:purpleaxis/dev_demo.git
purpleaxis
dev_demo
dev_demo
master

搜索帮助