scrollable_positioned_list 0.3.8 copy "scrollable_positioned_list: ^0.3.8" to clipboard
scrollable_positioned_list: ^0.3.8 copied to clipboard

A list with helper methods to programmatically scroll to an item.

scrollable_positioned_list #

A flutter list that allows scrolling to a specific item in the list.

Also allows determining what items are currently visible.

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,
);
copied to clipboard

One then can scroll to a particular item with:

itemScrollController.scrollTo(
  index: 150,
  duration: Duration(seconds: 2),
  curve: Curves.easeInOutCubic);
copied to clipboard

or jump to a particular item with:

itemScrollController.jumpTo(index: 150);
copied to clipboard

One can monitor what items are visible on screen with:

itemPositionsListener.itemPositions.addListener(() => ...);
copied to clipboard

Experimental APIs (subject to bugs and changes) #

Changes in scroll position can be monitored with:

scrollOffsetListener.changes.listen((event) => ...)
copied to clipboard

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));
copied to clipboard

A full example can be found in the example folder.


This is not an officially supported Google product.

1.9k
likes
140
points
1.66M
downloads

Publisher

verified publishergoogle.dev

Weekly Downloads

2024.09.08 - 2025.03.23

A list with helper methods to programmatically scroll to an item.

Repository (GitHub)
Contributing

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

collection, flutter

More

Packages that depend on scrollable_positioned_list