ListController class

Interface to the sliver list.

List controller can be used to

  • jump or animate to a specific item in the list
  • query the extent of an item
  • query total number of item as well as number of items with estimated extents
  • invalidate extent of an item to force recalculation

List controller can only be attached to a single SuperSliverList at a time. All methods except isAttached will throw if the controller is not attached.

List controller is also a ChangeNotifier and will notify its listeners if the underlying list or item extents change.

Example usage:

class _MyState extends State<MyWidget> {
 final _listController = ListController();
 final _scrollController = ScrollController();

 @override
 Widget build(BuildContext context) {
   return SuperListView.builder(
     listController: _listController,
     controller: _scrollController,
     itemCount: 1000,
     itemBuilder: (context, index) {
       return ListTile(title: Text('Item $index'));
     },
   );
 }

 void jumpToItem(int index) {
   _listController.jumpToItem(
     index: index,
     scrollController: _scrollController,
     alignment: 0.5,
   );
 }
}
Inheritance

Constructors

ListController({VoidCallback? onAttached, VoidCallback? onDetached})

Properties

hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
isAttached bool
Returns true if the controller is attached to a SuperSliverList.
no setter
isLocked bool
Returns whether the underlying list is currently locked.
no setter
numberOfItems int
Returns the total number of items in the list.
no setter
numberOfItemsWithEstimatedExtent int
Returns the number of items in the list with estimated extent.
no setter
onAttached VoidCallback?
Callback invoked when the controller is attached to a SuperSliverList.
final
onDetached VoidCallback?
Callback invoked when the controller is detached from a SuperSliverList.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
totalExtent double
Returns the sum of all the extents of the items in the list.
no setter
unobstructedVisibleRange → (int, int)?
Returns range of items indices currently visible in the viewport unobstructed by sticky headers or other obstructions.
no setter
visibleRange → (int, int)?
Returns the range of items indices currently visible in the viewport.
no setter

Methods

addItem(int index) → void
Signals that a new item has been added to the list at index. This shift all extents after the index by one and will create new estimated extent for the new item.
addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
animateToItem({required int index, required ScrollController scrollController, required double alignment, required Duration duration(double estimatedDistance), required Curve curve(double estimatedDistance), Rect? rect}) → void
Animates the position of the scroll view such that the item at index is revealed in the viewport.
dispose() → void
Discards any resources used by the object.
override
extentForIndex(int index) → (double, bool)
Returns the extent of the item at index.
getOffsetToReveal(int index, double alignment, {Rect? rect}) double
invalidateAllExtents() → void
Invalidates the extent of all items in the list. All extents will be treated as estimations and will be recalculated if the ExtentPrecalculationPolicy allows for eagerly precalculating extents.
invalidateExtent(int index) → void
Invalidates the extent of the item at index. Invalidating extent will treat the extent as an estimation and will recalculate the extent if the ExtentPrecalculationPolicy allows for eagerly precalculating extents.
jumpToItem({required int index, required ScrollController scrollController, required double alignment, Rect? rect}) → void
Immediately positions the scroll view such that the item at index is revealed in the viewport.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeItem(int index) → void
Signals that an item has been removed from the list at index. This shift all extents after the index by one and will remove the extent of the removed item.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
setDelegate(ExtentManager delegate) → void
toString() String
A string representation of this object.
inherited
unsetDelegate(ExtentManager delegate) → void

Operators

operator ==(Object other) bool
The equality operator.
inherited