flutter_infinite_listview icon indicating copy to clipboard operation
flutter_infinite_listview copied to clipboard

Add snaping functionality

Open Hannnes1 opened this issue 4 years ago • 0 comments

We needed this functionality in one of our apps, so I implemented it into this package. It's up to the maintainers to decide if this is suitable for their package, but I thought that I might as well open a pull request since I had to make this anyway.

To make the list snap, I created a new named constructor, InfiniteListView.snapping. The reason for creating a new constructor is that this feature does not work with separators, and itemExtent needs to be non-null. I could have asserted that itemExtent is not null when snap is true in the InfiniteListView.builder constructor, but I think that that approach is less clear an more prone to errors.

When snap is set to true in the constructor, the list will animate to the closest child in the scroll direction when the delta between the two latest scroll events is below snapTreshold and run the onSnap callback.

I have edited the example app to show this feature in action.

Hannnes1 avatar Aug 07 '21 14:08 Hannnes1