Skip to content

fix(ListViewObserver): support SliverPrototypeExtentList - #159

Merged
LinXunFeng merged 3 commits into
mainfrom
LinXunFeng/feature-request-support-for-reorderablelistview
Sep 13, 2026
Merged

LinXunFeng merged 3 commits into
mainfrom
LinXunFeng/feature-request-support-for-reorderablelistview

Conversation

@LinXunFeng

Copy link
Copy Markdown
Member

Related Issues

Description

ReorderableListView is a CustomScrollView with a SliverReorderableList inside, which builds one of the following slivers depending on its parameters:

Parameter RenderSliver Before
(default) RenderSliverList
itemExtent RenderSliverFixedExtentList
itemExtentBuilder RenderSliverVariedExtentList
prototypeItem _RenderSliverPrototypeExtentList

So ListViewObserver already works with ReorderableListView, except when prototypeItem is used. The same applies to ListView(prototypeItem:).

Root cause. ListViewObserver.isSupportRenderSliverType only accepts RenderSliverList, RenderSliverFixedExtentList, and RenderSliverVariedExtentList (matched by its runtimeType string). The private _RenderSliverPrototypeExtentList is none of them, so the sliver context is never found, and both observation and jumpTo/animateTo silently do nothing.

Fix. Check the public abstract base class RenderSliverFixedExtentBoxAdaptor instead, which all three fixed-extent slivers extend:

return obj is RenderSliverList || obj is RenderSliverFixedExtentBoxAdaptor;

This also removes the runtimeType.toString() comparison, which may not match under --obfuscate since class names are obfuscated.

Compatibility

  • RenderSliverFixedExtentBoxAdaptor already exists in Flutter 3.7.0 (the minimum supported version), and _RenderSliverPrototypeExtentList extends it there. RenderSliverVariedExtentList extends it since it was added in 3.16.0. Verified against the 3.7.0 and 3.16.0 sources.
  • No public API changes.
  • Behaviour change for slivers that were previously ignored:
    • They are now picked up by the automatic sliver lookup, so they show up in onObserveAll, and may become the first sliver used by onObserve and jumpTo without sliverContext.
    • SliverViewObserver.extendedHandleObserve is no longer called for them, because the built-in list handling takes over.
    • customTargetRenderSliverType, sliverListContexts, and customHandleObserve still take precedence.

Example

Add ListView - Reorderable demo: drag to reorder, then jump to the item whose value is 50 via items.indexOf. A switch in the app bar toggles prototypeItem, and calls observerController.reattach() because the sliver type changes.

Tests

  • Scroll to index > Fixed height with prototypeItem (ListView)
  • Scroll to index > ReorderableListView > Dynamic height
  • Scroll to index > ReorderableListView > Fixed height with prototypeItem

Both prototypeItem cases fail without the fix.

  • flutter test - 86 passed
  • flutter analyze - no issues in lib/, test/ and example/
  • dart format --set-exit-if-changed lib/ test/
  • Run the example on the iOS simulator (Flutter 3.47.1, iPhone 17 Pro Max, iOS 26.5)
  • Build and run a minimal ReorderableListView app depending on this branch with Flutter 3.7.0 on the same simulator

@LinXunFeng
LinXunFeng merged commit 3e2fbf5 into main Sep 13, 2026
2 checks passed
@LinXunFeng
LinXunFeng deleted the LinXunFeng/feature-request-support-for-reorderablelistview branch September 13, 2026 16:39
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