Scroll Drag Detector

Pub Version Coverage lintervention_badge Bluesky

A special version of GestureDetector that picks up overscrolling ScrollViews inside of it.

Unlocks easy draggable scrollable sheets in Flutter.

Installation 💻

❗ In order to start using Scroll Drag Detector you must have the Dart SDK installed on your machine.

Or install via dart pub:

dart pub add scroll_drag_detector

Usage

Choose how movement in each physical direction is routed:

ScrollDragDetector(
  up: ScrollDragMode.dragFirst,
  down: ScrollDragMode.boundaryStart,
  left: ScrollDragMode.none,
  right: ScrollDragMode.none,
  onVerticalDragUpdate: (details, wouldScroll) {
    // Move the surrounding draggable.
  },
  child: scrollable,
)

Use ScrollDragMode.scrollFirst to let the child reach its boundary before the surrounding draggable takes over. Use ScrollDragDetector.legacy to migrate the previous scrollableCanMoveBack and onlyDragWhenScrollWasAtTop configuration without changing conventional sheet behavior.

Overriding child scroll behavior

When a child overrides its scroll behavior, wrap it in ScrollDragBehavior so the detector can still stop scrolling during a drag:

ScrollConfiguration(
  behavior: ScrollDragBehavior(
    parent: const ScrollBehavior().copyWith(scrollbars: false),
  ),
  child: ListView.builder(itemBuilder: buildItem),
)

The wrapper also works with per-view overrides such as CustomScrollView(scrollBehavior: ScrollDragBehavior(parent: customBehavior)). It preserves the consumer's settings, including copyWith(...) overrides, and delegates unchanged when there is no ancestor detector.