Flutter:如何防止意外拖动一个可拖动对象,该对象是SingleChildScrollView的子对象,从移动可拖动



我在SingleChildScrollView中有可拖拽的小部件,为了防止当用户的意图是滚动时拖拽Draggable,我想把它们改成LongPressDraggable,延迟,代码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) {
...
})

问题是每当LongPressDraggable的延迟属性存在时,它的子GestureDetector的onTap不会触发。即使延迟设置为0,也可以使其与Draggable相同。

如何解决这个问题?或者是否有更好的方法来防止拖动在SingleChildScrollView中的可拖动拖动而不是滚动?

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

如果我理解正确的话,您想禁用SingleChildScrollView()内的子元素的滚动属性吗?

尝试在您的孩子可滚动部件中设置physicsNeverScrollableScrollPhysics()