Flutter:如何防止意外地拖动单层Crollview的孩子,而不是滚动而不是滚动?
我在单个单元格式内有可拖动的小
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) {
...
})
部件GETUREDETECTOR的ONTAP不会触发。即使将延迟设置为0,也可以使其与可拖动相同。
我该如何解决这个问题?还是有更好的方法可以防止在单层Crollview中拖动可拖动,而不是滚动?
更新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,
),
),
),
)
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,
),
),
),
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解它,您想禁用儿童在
singlechildscrollview()
内的滚动属性吗?尝试设置
物理
neverscrollablesscrollphysics()
在您的孩子可滚动小部件中。If I understand it correctly, you want to disable the scrolling property of the child inside
SingleChildScrollView()
?Try setting
physics
toNeverScrollableScrollPhysics()
in your child scrollable widget.