superlistapp / super_sliver_list

Drop-in replacement for SliverList and ListView that can handle large amount of items with variable extents and reliably jump / animate to any item.
https://superlistapp.github.io/super_sliver_list/
MIT License
277 stars 15 forks source link

Feature: Get visible items by a controller #23

Closed amrgetment closed 6 months ago

amrgetment commented 6 months ago

I wonder how to get the first visible item to update the side alphabets for the contacts list like Google or Samsung contacts?

image

amrgetment commented 6 months ago

You could try to scroll through contacts on your mobile to get the idea about why I need it

knopp commented 6 months ago

I understand the usecase. Would need to figure out what the proper API for this would look like. Btw. there are packages such as visibility detector that might be usable for something like this, but in general doing this on sliver level would probably be fastest.

amrgetment commented 6 months ago

@knopp Thanks for your effort in adding this feature so I can almost replace the Google scrollable_positioned_list library Now I can get the first visible items to update the side alphabet bar I will replace itemPositionsListener by ScrollController listener

  widget.itemPositionsListener.itemPositions.addListenerWithCloser(this,
          () {
        if (widget.itemPositionsListener.itemPositions.value.isNotEmpty) {
          final double scrollableItemIndex =
              _getFirstScrollableItem().toDouble();
          if (scrollableItemIndex != _currentSliderValue) {
            setState(() {
              _currentSliderValue = scrollableItemIndex;
            });
          }
        }
      });

I will let you know if I was able to replace it successfully

Thanks again for your effort