4

I have Draggable widgets inside a SingleChildScrollView and to prevent the Draggable from being dragged when users' intention is to scroll, I thought to change them into LongPressDraggable with a delay, code blow:

         LongPressDraggable(
            delay: Duration(milliseconds: 200),
            axis: Axis.vertical,
            data: block,
            feedback: Opacity(
              opacity: kScheduledBlockFeedbackOpacity,
              child: Material(
                elevation: 10.0,
                shadowColor: Colors.black,
                child: scheduleBlock(block, scheduledBlockFeedbackColor),
              ),
            ),
            child: GestureDetector(
              onTap: () {
                print('onTap triggered 1');
                // go to details
                ...
              },
              child: block.action == 'pulling'
                  ? Opacity(opacity: kScheduledBlockFeedbackOpacity, child: scheduleBlock(block, scheduledBlockColor))
                  : scheduleBlock(block, scheduledBlockColor),
            ),

            childWhenDragging: Container(),
            onDragStarted: () {
              ...
            },
            onDragUpdate: (DragUpdateDetails d) {
              ...
            },
            onDragEnd: (DraggableDetails d) {
              ...
            })

The problem is whenever the LongPressDraggable's delay property is present, its child GestureDetector's onTap doesn't trigger. Even if the delay is set to 0, making it work with same as a Draggable.

How can I get around this problem? Or is there a better way to prevent dragging on a Draggable within a SingleChildScrollView from moving the Draggable instead of scrolling?

Update 5/31/23

                        Positioned(
                          child: LongPressDraggable(
                            axis: Axis.vertical,
                            // feedbackOffset: Offset(0, offSet),
                            onDragStarted: () {},
                            onDragUpdate: (DragUpdateDetails d) {},
                            onDragEnd: (DraggableDetails d) {},
                            childWhenDragging: Container(height: block.duration),
                            data: block,
                            child: Column(
                              children: [
                                // block.moved
                                selectedID == block.id
                                    ? LongPressDraggable()
                                    : DragTarget(builder: (context, candidateItems, rejectedItems) {}, 
                                    onMove: (DragTargetDetails d) {
                                        setState(() {});
                                      }),
                              ],
                            ),
                            // childWhenDragging: Container(),
                            feedback: Opacity(
                              opacity: opacity,
                              child: Material(
                                elevation: elevation,
                                shadowColor: Colors.black,
                                child: child,
                              ),
                            ),
                          ),
                        )
Chuender
  • 103
  • 9
  • Did you ever find a solution to this? I'm running into the exact same thing. – Clifton Labrum May 12 '23 at 21:36
  • Sorry for the late reply, @CliftonLabrum. I updated my post with what ended up working for me. It was a while a go so I hope this helps - by necessity I had to make the child of the LongPressDraggable either a DragTarget or a LongPressDraggable, and then noticed that this happily fixed the issue I had posted here. – Chuender May 31 '23 at 00:53
  • That's exactly the solution I ended up finding. Thank you! – Clifton Labrum May 31 '23 at 04:35

1 Answers1

0

If I understand it correctly, you want to disable the scrolling property of the child inside SingleChildScrollView()?

Try setting physics to NeverScrollableScrollPhysics() in your child scrollable widget.

Yash Garg
  • 477
  • 5
  • 11
  • 1
    I want to prevent accidental dragging of a child inside SingleChildScrollView when user actually wants to scroll the scroll view – Chuender May 01 '22 at 01:05