如何用另一个 GestureDetector 包装 GestureDetector 并在任何地方获取事件

How to wrap GestureDetector with another GestureDetector and get events everywhere

如果我的 GestureDetector 具有内部 GestureDetector,我该如何设置它以便两个检测器都能接收到点击事件?

您可以在此处查看 运行 代码: https://dartpad.dev/37807a51a48e52eda81c24cf67260c33

GestureDetector(
      onTap: () => print("Log 1"),
      child: GestureDetector(
        onTap: () => print("Log 2"),
        child: Text("CLICK ME")
      )
);
    class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return RawGestureDetector(
        gestures: {
          AllowMultipleVerticalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<
              AllowMultipleVerticalDragGestureRecognizer>(
            () => AllowMultipleVerticalDragGestureRecognizer(),
            (AllowMultipleVerticalDragGestureRecognizer instance) {
              instance..onEnd = (_) => print("test1");
            },
          )
        },
        child: RawGestureDetector(
          gestures: {
            AllowMultipleVerticalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<
                AllowMultipleVerticalDragGestureRecognizer>(
              () => AllowMultipleVerticalDragGestureRecognizer(),
              (AllowMultipleVerticalDragGestureRecognizer instance) {
                instance..onEnd = (_) => print("test2");
              },
            )
          },
          child: Container(color: Colors.red),
        ));
  }
}

class AllowMultipleVerticalDragGestureRecognizer extends VerticalDragGestureRecognizer{
  @override
  void rejectGesture(int pointer) {
    acceptGesture(pointer);
  }
}

来源:https://gist.github.com/Nash0x7E2/08acca529096d93f3df0f60f9c034056