我在SingleChildScrollView中有可拖动的小部件,为了防止用户想要滚动时拖动,我想将它们更改为LongPressDraggable,并延迟,代码如下:
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的delay属性存在,其子GestureDetector的onTap就不会触发。即使延迟被设置为0,使其与Draggable一样工作。
我怎样才能解决这个问题?或者有没有更好的方法来防止在SingleChildScrollView中拖动Draggable来移动Draggable而不是滚动?
更新日期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,
),
),
),
)
1条答案
按热度按时间83qze16e1#
如果我没理解错的话,你想禁用
SingleChildScrollView()
内部子元素的滚动属性?尝试在子滚动窗口中将
physics
设置为NeverScrollableScrollPhysics()
。