Skip to content

feat: add pull-to-refresh to scrollable controls - #27

Merged
AdamMusa merged 2 commits into
codex/engine-initializationfrom
feat/pull-to-refresh
Oct 29, 2026
Merged

AdamMusa merged 2 commits into
codex/engine-initializationfrom
feat/pull-to-refresh

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Package A / A1 (pull-to-refresh, P0). Ruby counterpart: AdamMusa/ruflet#43. Implements lead decision D-2.

What

ListView, GridView and Column with on_refresh render a CustomScrollView with a native refresh control.

  • Material: RefreshIndicator
  • Cupertino: CupertinoSliverRefreshControl as the first sliver, with bouncing physics. No Material widget is used.

A shared RefreshCoordinator fires refresh and keeps the spinner until Ruby invokes end_refresh. Ruby sends that automatically once the handler returns (D-2). refresh_timeout (default 30 s) is the safety net if the acknowledgement never arrives.

New files: refresh_coordinator.dart, scroll_slivers.dart, material_refresh_scroll_view.dart, cupertino_refresh_scroll_view.dart, adaptive_refresh_scroll_view.dart.

  • Same geometry as without refresh. scroll_slivers.dart rebuilds the exact slivers ListView/GridView build internally: explicit padding, or the BoxScrollView main-axis media padding when padding is nil, plus spacing/separators, item_extent, prototype, build_controls_on_demand. grid_view.dart now takes its delegate from gridDelegateFor and list_view.dart its separator from listSeparator.
  • Same controller. scroll, auto_scroll, scroll_to and on_scroll keep working on a refreshable list. The refresh path is an early return inside the existing LayoutBuilder, so the box ListView/GridView code is untouched apart from a shared _scrollable() wrapper.
  • Column. A refreshable Column always scrolls vertically, through a small _RefreshableColumn that owns the controller. The Column sits in a box at least one viewport tall, so alignment still works. If a child has expand, the box is exactly one viewport tall so Expanded keeps flexing; an unbounded box would throw.
  • Horizontal or reverse lists and wrap: true Columns ignore on_refresh and log one debugPrint.

Ruby usage

feed = list_view(expand: true, spacing: 8, padding: 16,
  controls: posts.map { |p| post_tile(p) },
  refresh_color: "#1E88E5",
  on_refresh: ->(_e) do
    feed.children.replace(Post.latest.map { |p| post_tile(p) })
    page.update            # end_refresh is sent automatically after this handler
  end)
page.add(feed)

Wire

Key Material Cupertino
on_refresh → event refresh, payload null RefreshIndicator CupertinoSliverRefreshControl
refresh_color RefreshIndicator.color CupertinoActivityIndicator color (copy of the SDK builder)
refresh_bgcolor backgroundColor ignored
refresh_displacement (40) displacement ignored
refresh_trigger_distance (100) ignored refreshTriggerPullDistance (kept ≥ the 60 px indicator extent)
refresh_timeout (ms or {seconds:}, 30 s) safety net safety net
invoke end_refresh (no args) completes the spinner completes the spinner

end_refresh is only answered by the coordinator's listener. Other names return null, so ScrollableControl's scroll_to listener keeps working.

Tests: test/widgets/ruby_refresh_test.dart, 33 tests on iOS and Android

  • Coordinator unit tests. A second pull joins the pending refresh, end_refresh completes it, other invoke names are ignored, refresh_timeout works, and dispose completes the refresh and unregisters the listener.
  • ListView, GridView and Column.
    • A drag fires exactly one refresh.
    • Material shows RefreshIndicator + RefreshProgressIndicator. Cupertino shows CupertinoSliverRefreshControl + CupertinoActivityIndicator, with no Material widget before, during or after the pull.
    • The spinner stays until end_refresh, then settles back to the top, and a second pull refreshes again.
  • Geometry.
    • ListView and GridView item rects are identical with and without on_refresh (padding, spacing, run_spacing).
    • Media-padding parity when padding is nil.
    • Column alignment: center + spacing positions are unchanged.
    • Column expand children keep their flex height.
  • Other cases.
    • refresh_timeout: 100 ends the spinner without Ruby.
    • A 2-item list can be pulled.
    • An unbounded, shrink-wrapped list refreshes.
    • Colors and distances reach the widgets.
    • Horizontal or reversed lists ignore on_refresh.
    • scroll_to works on a refreshable list.

The matrix fixtures are unchanged, as the spec says. The no-Material-on-Cupertino rule for the refresh path is asserted in the focused test with a stricter predicate that includes RefreshIndicator and ProgressIndicator.

verify_pr.sh (Flutter 3.41.2):

  • engine +728: All tests passed!
  • flutter analyze lib test: No issues found!
  • ruflet_core 147/147 files, 633 runs
  • wire-key audit: NEW vs baseline = 2. Both are the pre-existing ReorderableListView spacing/divider_thickness lines; only their "literal elsewhere" hint changed, because those literals moved into scroll_slivers.dart. There are no new findings, and every new refresh key is read.

Notes and deviations from SPEC

  • boxSliver uses a min-height SliverToBoxAdapter instead of SliverFillRemaining(hasScrollBody: false). SliverFillRemaining measures the child's intrinsic height, which throws for LayoutBuilder-based children (ListView, GridView, ResponsiveRow, Markdown…) and costs an extra layout pass.
  • On iOS a shrink-wrapped (unbounded) list has a small viewport, so bouncing friction is higher and the pull has to be longer. expand: true is still recommended.
  • Reviewers of later items: E1 (CustomScrollView) should reuse scroll_slivers.dart and adaptive_refresh_scroll_view.dart.

ListView, GridView and Column with on_refresh render a CustomScrollView
with a Material RefreshIndicator or, on Cupertino, a
CupertinoSliverRefreshControl. A shared RefreshCoordinator fires the
refresh event and keeps the spinner until Ruby invokes end_refresh, with
refresh_timeout (30 s) as a safety net. The slivers reproduce the box
ListView/GridView layout (padding, media insets, spacing, separators,
item extents) so geometry is unchanged, and the scroll controller is
shared so scroll, auto_scroll, scroll_to and on_scroll keep working.
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