Skip to content

feat: add on_end_reached infinite scroll to scrollable controls - #30

Merged
AdamMusa merged 2 commits into
codex/engine-initializationfrom
feat/end-reached
Oct 29, 2026
Merged

AdamMusa merged 2 commits into
codex/engine-initializationfrom
feat/end-reached

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Package A / A2 (end-reached). Ruby counterpart: AdamMusa/ruflet#45.

Depends on #27 (A1 pull-to-refresh): stacked so the listener also wraps the refreshable sliver view and the shared _scrollable() wrapper. Review only the top commit, feat: add on_end_reached infinite scroll to scrollable controls.

What

New neutral controls/end_reached_listener.dart (EndReachedListener). It wraps the scroll view of ListView, GridView, Column and Row next to ScrollNotificationControl, and only when on_end_reached is set.

  • It listens to ScrollNotification and to ScrollMetricsNotification. The latter is dispatched after the first layout and whenever the content size changes. Only depth 0 is considered, and notifications are never absorbed.
  • It fires end_reached once when extentAfter <= end_reached_threshold (default 200 px). That includes right after the first frame when the content is shorter than the viewport.
  • It re-arms when maxScrollExtent grows past the value it fired for (Ruby appended items), or when the user scrolls more than twice the threshold away from the end, so a failed load can be retried.
  • A reverse: true list (chat) reaches its end at the visual top, which is the "load older messages" case.

Ruby usage

feed = list_view(expand: true, end_reached_threshold: 300,
  controls: first_page.map { |p| post_tile(p) },
  on_end_reached: ->(e) do
    next_page(after: feed.children.length).each { |p| feed.children << post_tile(p) }
    page.update
  end)

Wire

  • Props: on_end_reached, end_reached_threshold (float px, default 200).
  • Event: end_reached with payload {"pixels", "max_scroll_extent", "viewport_dimension"}.

Material vs Cupertino

The behavior is identical. The listener is widgets-layer only and works for box scroll views, SingleChildScrollView (Column/Row with scroll:) and the pull-to-refresh CustomScrollView. Column and Row only have a scroll view when scroll: (or, for Column, on_refresh) is set.

Tests: test/widgets/ruby_end_reached_test.dart, 18 tests on iOS and Android

  • ListView, GridView, Column and Row:
    • Nothing fires at the top, or at 150 px from the end with a 100 px threshold.
    • Exactly one event fires inside the threshold, with an exact payload.
    • No re-fire while moving around near the end.
    • Appending a page through a real controls patch fires again only when the new end is reached.
    • Scrolling back more than twice the threshold re-arms.
  • A short list fires once after the first frame.
  • A fling-drag to the end fires.
  • A reversed list ends at the top.
  • It works together with on_refresh.
  • Nothing is sent without on_end_reached.

Results:

  • engine flutter test +746: All tests passed! (A1 728 + 18)
  • flutter analyze lib test: No issues found!
  • ruflet_core 148/148 files, 638 runs
  • wire-key audit: no new findings. The 2 textual diffs are hint-list changes on pre-existing ReorderableListView lines.

ListView, GridView, Column and Row with on_end_reached fire end_reached
once when the trailing edge comes within end_reached_threshold (200 px by
default), including right after the first layout of a short list. It
re-arms when the content grows or the user scrolls more than twice the
threshold away, and works with the pull-to-refresh sliver view.
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.

1 participant