gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 04:52:59 27 4
gpt4 key购买 nike

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

你可以在这里看到运行代码: https://dartpad.dev/37807a51a48e52eda81c24cf67260c33

GestureDetector(
onTap: () => print("Log 1"),
child: GestureDetector(
onTap: () => print("Log 2"),
child: Text("CLICK ME")
)
);
  • 每次我点击它打印的文本 Log 2

  • 我已经尝试设置 HitTestBehavior.traslucent 和所有这些但没有成功。

  • 我希望它打印Log 1Log 2

最佳答案

    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

关于flutter - 如何用另一个 GestureDetector 包装 GestureDetector 并在任何地方获取事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66285602/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com