Skip to content
pubscout

scroll_spy

2.0.0, released 6 weeks ago by tomars.tech

Detect visible items and select one stable primary item in Flutter scrollables.

WASM-ready
$ flutter pub add scroll_spy
Source repository

What it does

Scroll_spy measures item positions in scrollable viewports, determines which items intersect a configurable attention region, and selects a single stable primary item using customizable policies and anti-flicker stability rules. It exposes granular notifiers for visibility, focus, and primary winner states without requiring manual geometry math.

AI-written summary of version 2.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You are building a video feed that needs autoplay for exactly one visible card at a time.
  • You need to highlight reading position or table of contents items based on viewport focus.
  • Multiple items are visible and you need hysteresis and anti-flicker rules to prevent rapid switching.

Skip it when

  • You only need basic visibility percentages for individual widgets without choosing a single primary winner.
  • Your application targets SDKs older than Flutter 3.47.7 and Dart 3.13.5.

Strengths

  • O(1) position derivation during steady scrolling using a cached scroll model without render-tree walks.
  • Built-in stability rules like hysteresis and minimum primary duration to prevent UI flickering.
  • Granular, lazy, and diff-optimized notifiers for high scroll performance.

Weaknesses

  • Requires updating to Flutter 3.47.7+ and Dart 3.13.5+ for version 2.0.0.
  • Adds overhead compared to raw visibility checks if you only need simple widget visibility reporting.

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
0
Scroll_spyListView<int>.builder(
  controller: _spy,
  region: ScrollSpyRegion.zone(
    anchor: const ScrollSpyAnchor.fraction(0.5),
    extentPx: 200,
  ),
  policy: const ScrollSpyPolicy<int>.closestToAnchor(),
  itemCount: 60,
  itemExtent: 220,
  itemBuilder: (context, index) {
    return ScrollSpyItem<int>(
      id: index,
      child: FeedCardBody(index: index),
    );
  },
)

Alternatives

Packages that do the same job and could replace scroll_spy.