第八章 8.3.5 HitTestBehavior 中 PointerDownEvent组件,其中一行代码bool hitTestSelf(Offset position) =>true; //始终通过命中测试,我将hitTestSelf返值改为false,为什么也能命中测试
ynahauH opened this issue · 0 comments
ynahauH commented
class RenderPointerDownListener extends RenderProxyBox {
PointerDownEventListener? onPointerDown;
@OverRide
bool hitTestSelf(Offset position) => true; //始终通过命中测试
@OverRide
void handleEvent(PointerEvent event, covariant HitTestEntry entry) {
//事件分发时处理事件
if (event is PointerDownEvent) onPointerDown?.call(event);
}
}
class PointerDownListenerRoute extends StatelessWidget {
const PointerDownListenerRoute({Key? key}) : super(key: key);
@OverRide
Widget build(BuildContext context) {
return PointerDownListener(
child: const Text('Click me'),
onPointerDown: (e) => print('down'),
);
}
}