Flutter: Disabling Multi-Touch/Drag with Gesture Detector

前端 未结 2 1438
温柔的废话
温柔的废话 2021-01-28 16:23

Im currently building a Slider widget which multiple handle and am currently implementing the Gesture Detector. I am having an issue where if you touch/drag the screen with a se

相关标签:
2条回答
  • 2021-01-28 16:49

    According to the class reference:

    Attempts to recognize gestures that correspond to its non-null callbacks.

    So if you write it like this:

    GestureDetector(
      onDragUpdate: (updateDetails) {
        // Single finger drag, update your handlers
      },
      onPanDown: (_){}, 
      onPanStart: (_){}, 
      onPanUpdate: (_){}, 
      onPanEnd: (_){}, 
      onPanCancel: (){},
      child: Container(
        color: Colors.yellow,
        child: Text('TURN LIGHTS ON'),
      ),
    )
    

    It won't react on multi-touch, so you don't have to disable anything

    UPD: according to question edit, you should set empty but non-null callbacks for all multi-touch events, so two fingers drag will be handled by empty callback, but single finger not

    0 讨论(0)
  • 2021-01-28 16:53

    Whilst I was working on another separate problem I happened to have also solved this problem by using the solution here

    0 讨论(0)
提交回复
热议问题