scrollable_positioned_list_plus
A Flutter list that can jump or scroll to a specific item, and report which items are visible.
This is a maintained successor of scrollable_positioned_list. Google archived its repository in 2024, so 0.3.8 (2023) is its final release. Bada Labs uses this package in production apps.
What's different from scrollable_positioned_list 0.3.8
- Works with current Flutter. 0.3.8 uses
cacheExtentandcacheExtentStyle, which Flutter 3.44 deprecated in favor ofScrollCacheExtentand will remove. This package uses the new API, with the same cache sizes. - No other deprecated APIs.
Matrix4.translate, pre-null-safety checks and adynamicequality operator are replaced with their current equivalents. - Same behavior. The original test suite (181 tests) runs in this repository and passes unchanged, apart from importing
unawaitedfromdart:asyncinstead of the retiredpedanticpackage. - Requires Flutter 3.44 or later, the first stable release with
ScrollCacheExtent.
Migrating from scrollable_positioned_list
- In
pubspec.yaml, replacescrollable_positioned_listwithscrollable_positioned_list_plus. - Replace
package:scrollable_positioned_list/withpackage:scrollable_positioned_list_plus/in your imports.
The API is unchanged.
Usage
A ScrollablePositionedList works much like the builder version of ListView
except that the list can be scrolled or jumped to a specific item.
Example
A ScrollablePositionedList can be created with:
final ItemScrollController itemScrollController = ItemScrollController();
final ScrollOffsetController scrollOffsetController = ScrollOffsetController();
final ItemPositionsListener itemPositionsListener = ItemPositionsListener.create();
final ScrollOffsetListener scrollOffsetListener = ScrollOffsetListener.create();
ScrollablePositionedList.builder(
itemCount: 500,
itemBuilder: (context, index) => Text('Item $index'),
itemScrollController: itemScrollController,
scrollOffsetController: scrollOffsetController,
itemPositionsListener: itemPositionsListener,
scrollOffsetListener: scrollOffsetListener,
);
One then can scroll to a particular item with:
itemScrollController.scrollTo(
index: 150,
duration: Duration(seconds: 2),
curve: Curves.easeInOutCubic);
or jump to a particular item with:
itemScrollController.jumpTo(index: 150);
One can monitor what items are visible on screen with:
itemPositionsListener.itemPositions.addListener(() => ...);
Experimental APIs (subject to bugs and changes)
Changes in scroll position can be monitored with:
scrollOffsetListener.changes.listen((event) => ...)
see ScrollSum in this test for an example of how the current offset can be
calculated from the stream of scroll change deltas. This feature is new and experimental.
Changes in scroll position in pixels, relative to the current scroll position, can be made with:
scrollOffsetController.animateScroll(offset: 100, duration: Duration(seconds: 1));
A full example can be found in the example folder.
Scope
This package fixes bugs and keeps up with Flutter changes. New features are considered conservatively to keep it small and dependable.
Credits
Based on scrollable_positioned_list by the Flutter widgets authors at Google, under the BSD 3-Clause license. Maintained by Bada Labs. This is not an officially supported Google product.
Libraries
- scrollable_positioned_list
- scrollable_positioned_list_plus
- A list with helper methods to programmatically scroll to an item.