Flutter:如何防止意外地拖动单层Crollview的孩子,而不是滚动而不是滚动?

发布于 2025-01-25 06:40:26 字数 2901 浏览 3 评论 0原文

我在单个单元格式内有可拖动的小

         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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七堇年 2025-02-01 06:40:26

如果我正确理解它,您想禁用儿童在singlechildscrollview()内的滚动属性吗?

尝试设置物理 neverscrollablesscrollphysics()在您的孩子可滚动小部件中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文