flutter_in_action_2nd icon indicating copy to clipboard operation
flutter_in_action_2nd copied to clipboard

第八章 8.3.5 HitTestBehavior 中 PointerDownEvent组件,其中一行代码bool hitTestSelf(Offset position) =>true; //始终通过命中测试,我将hitTestSelf返值改为false,为什么也能命中测试

Open ynahauH opened this issue 2 years ago • 0 comments

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'), ); } }

ynahauH avatar Aug 14 '23 03:08 ynahauH