Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 7, 2025

Drag-to-select stops working when scrolling to the second page because gesture detectors were attached per-item in SliverChildBuilderDelegate, only receiving events for mounted items.

Changes

Moved gesture detection from per-item to scroll view level

  • Wrapped CustomScrollView with a single GestureDetector handling all drag/pan/longpress events
  • Removed per-item gesture detectors from sliverGrid builder (~75 lines)

Refactored coordinate calculation in AssetGridDragSelectionCoordinator

  • Extracted _calculateIndexFromPosition() to compute grid indices from global screen coordinates
  • Updated onSelectionStart() to accept BoxConstraints instead of index/asset parameters, calculating them from position
  • Simplified onSelectionUpdate() to reuse shared position calculation (~80 lines of duplication removed)

How it works

// Before: Gesture detector on each item, limited to mounted items
child = GestureDetector(
  onHorizontalDragStart: (d) => coordinator.onSelectionStart(
    index: index,  // Only works for this specific mounted item
    asset: assets[index],
  ),
  child: child,
);

// After: Global gesture detector calculates index from position
GestureDetector(
  onHorizontalDragStart: (d) => coordinator.onSelectionStart(
    globalPosition: d.globalPosition,  // Works for any position
    constraints: constraints,
  ),
  child: CustomScrollView(...),
)

The position-to-index calculation accounts for grid parameters (count, spacing), scroll offset, reverted layouts, and special items, working independently of item mounting state.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://storage.googleapis.com/flutter_infra_release/flutter/a5cb96369ef86c7e85abf5d662a1ca5d89775053/dart-sdk-linux-x64.zip
    • Triggering command: /usr/bin/curl curl --retry 3 --continue-at - --location --output /tmp/flutter/bin/cache/dart-sdk-linux-x64.zip REDACTED (http block)
    • Triggering command: /usr/bin/curl curl --retry 3 --continue-at - --location --output /tmp/flutter_test/flutter_sdk/bin/cache/dart-sdk-linux-x64.zip REDACTED (http block)
    • Triggering command: /usr/bin/curl curl --retry 3 --location --output /tmp/flutter_test/flutter_sdk/bin/cache/dart-sdk-linux-x64.zip REDACTED ndor/bin/git (http block)
  • https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.24.5-stable.tar.xz
    • Triggering command: /usr/bin/wget wget -q REDACTED -O flutter.tar.xz (http block)
  • https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.27.1-stable.tar.xz
    • Triggering command: /usr/bin/curl curl -L REDACTED --output flutter.tar.xz --progress-bar (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[BUG] 拖拽选择到第二页会停止</issue_title>
<issue_description>Describe the bug
拖拽选择图片,滑动到第二页无法继续选择
https://github.com/user-attachments/assets/94d7241e-4987-4998-81a5-2b91d1ba80c0

How to reproduce
WeChat Assets Picker 示例

Version information

  • WeChat Assets Picker: [v9.5.0]
  • Flutter Version: [v3.24.1]
    </issue_description>

Comments on the Issue (you are @copilot in this section)

@AlexV525 This is limited by the current implementation of the auto-scroll gesture. It needs a refactor to determine scroll positions globally to get rid of the item mounting state. @AlexV525 > 感觉可以参考这个库的实现:[drag_select_grid_view](https://pub.dev/packages/drag_select_grid_view)

该项目相较于参考的库而言复杂度不在同一个等级,需要调研层级调整对 delegate 整体交互效果的影响。</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix dragging selection issue on second page Fix drag selection stopping when scrolling beyond visible items Dec 7, 2025
Copilot AI requested a review from AlexV525 December 7, 2025 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] 拖拽选择到第二页会停止

2 participants