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,
),
),
),
)